title: auto
des: auto note:auto
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
import { getConfig } from '@/bin/config';
|
import { getConfig } from "@/bin/config";
|
||||||
import { unsealData } from 'iron-session';
|
import { unsealData } from "iron-session";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import yaml from "yaml";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from 'path'
|
||||||
|
const config = yaml.parse(
|
||||||
|
fs.readFileSync("config.yaml").toString()
|
||||||
|
);
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const c = cookies().get("ssn");
|
const c = cookies().get("ssn");
|
||||||
const data = JSON.parse(
|
const data = JSON.parse(
|
||||||
await unsealData(c?.value as string, {password: ((await getConfig()).server.password)})
|
await unsealData(c?.value as string, { password: config.server.password })
|
||||||
)
|
);
|
||||||
return NextResponse.json(data);
|
return NextResponse.json({});
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/app_modules/home/fun/get-token.ts
Normal file
16
src/app_modules/home/fun/get-token.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"use server";
|
||||||
|
|
||||||
|
import prisma from "@/app/lib/prisma";
|
||||||
|
import { getConfig } from "@/bin/config";
|
||||||
|
import { unsealData } from "iron-session";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
|
export async function getToken() {
|
||||||
|
const c = cookies().get("ssn");
|
||||||
|
|
||||||
|
const token = await unsealData(c?.value as string, {
|
||||||
|
password: (await getConfig()).server.password,
|
||||||
|
});
|
||||||
|
|
||||||
|
return token
|
||||||
|
}
|
||||||
@@ -5,24 +5,32 @@ import { Logout } from "../auth";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ApiHipmi } from "@/app/lib/api";
|
import { ApiHipmi } from "@/app/lib/api";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
import { getToken } from "./fun/get-token";
|
||||||
|
|
||||||
export default function HomeView() {
|
export default function HomeView() {
|
||||||
const [token, setToken] = useState<any | null>(null);
|
const [token, setToken] = useState<any | null>(null);
|
||||||
|
|
||||||
|
// useShallowEffect(() => {
|
||||||
|
// userToken();
|
||||||
|
// }, []);
|
||||||
|
|
||||||
|
// async function userToken() {
|
||||||
|
// await fetch(ApiHipmi.get_token)
|
||||||
|
// .then((res) => res.json())
|
||||||
|
// .then((val) => setToken(val));
|
||||||
|
// }
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
userToken();
|
getUserId();
|
||||||
}, []);
|
}, []);
|
||||||
|
async function getUserId() {
|
||||||
async function userToken() {
|
const data = await getToken();
|
||||||
await fetch(ApiHipmi.get_token)
|
setToken(data);
|
||||||
.then((res) => res.json())
|
|
||||||
.then((val) => setToken(val));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* <pre>{JSON.stringify(token, null, 2)}</pre> */}
|
<pre>{JSON.stringify(token, null, 2)}</pre>
|
||||||
<Title>Home</Title>
|
<Title>Home</Title>
|
||||||
<Text>Welcome, {token?.username}</Text>
|
<Text>Welcome, {token?.username}</Text>
|
||||||
<Logout />
|
<Logout />
|
||||||
|
|||||||
Reference in New Issue
Block a user