title: auto

des: auto
note:auto
This commit is contained in:
2023-10-03 11:00:16 +08:00
parent ab1bb590bf
commit fa46a3f055
7 changed files with 30 additions and 34 deletions

View File

@@ -6,8 +6,11 @@ import { NextResponse } from "next/server";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { getConfig } from "@/bin/config"; import { getConfig } from "@/bin/config";
export async function POST(req: Request) { import fs from "fs";
import yaml from "yaml";
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
export async function POST(req: Request) {
if (req.method === "POST") { if (req.method === "POST") {
const body = await req.json(); const body = await req.json();
// MyConsole(body); // MyConsole(body);
@@ -37,7 +40,7 @@ export async function POST(req: Request) {
username: data.username, username: data.username,
}), }),
{ {
password: (await getConfig()).server.password, password: await config.server.password,
} }
); );

View File

@@ -4,11 +4,15 @@ import { NextResponse } from "next/server";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { sealData, unsealData } from "iron-session"; import { sealData, unsealData } from "iron-session";
import { getConfig } from "@/bin/config"; import { getConfig } from "@/bin/config";
import yaml from "yaml";
import fs from "fs";
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
export async function POST(req: Request) { export async function POST(req: Request) {
if (req.method === "POST") { if (req.method === "POST") {
const body = await req.json(); const body = await req.json();
myConsole(body);
const data = await prisma.user.findUnique({ const data = await prisma.user.findUnique({
where: { where: {
@@ -22,6 +26,8 @@ export async function POST(req: Request) {
}, },
}); });
myConsole(data)
if (!data) return NextResponse.json({ status: 404 }); if (!data) return NextResponse.json({ status: 404 });
if (data) { if (data) {
@@ -31,15 +37,10 @@ export async function POST(req: Request) {
username: data.username, username: data.username,
}), }),
{ {
password: (await getConfig()).server.password, password: (await config.server.password),
} }
); );
const un = await unsealData(res, {
password: (await getConfig()).server.password,
});
// console.log(JSON.stringify(un), "route validasi")
cookies().set({ cookies().set({
name: "ssn", name: "ssn",
value: res, value: res,

View File

@@ -1,18 +0,0 @@
import { getConfig } from "@/bin/config";
import { unsealData } from "iron-session";
import { cookies } from "next/headers";
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() {
const c = cookies().get("ssn");
const data = JSON.parse(
await unsealData(c?.value as string, { password: config.server.password })
);
return NextResponse.json({});
}

View File

@@ -3,7 +3,12 @@ import { useShallowEffect } from "@mantine/hooks";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import {unsealData} from "iron-session" import { unsealData } from "iron-session";
import { getConfig } from "@/bin/config";
import yaml from "yaml";
import fs from "fs";
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
export default async function PageSplash() { export default async function PageSplash() {
const c = cookies().get("ssn"); const c = cookies().get("ssn");
@@ -11,14 +16,12 @@ export default async function PageSplash() {
? null ? null
: JSON.parse( : JSON.parse(
await unsealData(c.value as string, { await unsealData(c.value as string, {
password: process.env.PWD as string, password: (await getConfig()).server.password,
}) })
); );
return ( return (
<> <>
<SplashScreen data={tkn} /> <SplashScreen data={tkn} />
</> </>
); );

View File

@@ -92,6 +92,7 @@ export default function Validasi() {
color="green" color="green"
onClick={() => { onClick={() => {
onValid(); onValid();
// myConsole("ok")
}} }}
> >
Submit Submit

View File

@@ -5,12 +5,18 @@ 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 fs from "fs";
import yaml from "yaml";
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
export async function getToken() { export async function getToken() {
const c = cookies().get("ssn"); const c = cookies().get("ssn");
const token = await unsealData(c?.value as string, { const token = await unsealData(c?.value as string, {
password: (await getConfig()).server.password, password: await config.server.password,
}); });
return token const data = JSON.parse(token as any)
return data;
} }

View File

@@ -30,7 +30,7 @@ export default function HomeView() {
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 />