title: auto
des: auto note:auto
This commit is contained in:
@@ -6,8 +6,11 @@ import { NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
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") {
|
||||
const body = await req.json();
|
||||
// MyConsole(body);
|
||||
@@ -37,7 +40,7 @@ export async function POST(req: Request) {
|
||||
username: data.username,
|
||||
}),
|
||||
{
|
||||
password: (await getConfig()).server.password,
|
||||
password: await config.server.password,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -4,11 +4,15 @@ import { NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
import { sealData, 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 async function POST(req: Request) {
|
||||
|
||||
if (req.method === "POST") {
|
||||
const body = await req.json();
|
||||
myConsole(body);
|
||||
|
||||
|
||||
const data = await prisma.user.findUnique({
|
||||
where: {
|
||||
@@ -22,6 +26,8 @@ export async function POST(req: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
myConsole(data)
|
||||
|
||||
if (!data) return NextResponse.json({ status: 404 });
|
||||
|
||||
if (data) {
|
||||
@@ -31,15 +37,10 @@ export async function POST(req: Request) {
|
||||
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({
|
||||
name: "ssn",
|
||||
value: res,
|
||||
|
||||
@@ -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({});
|
||||
}
|
||||
@@ -3,7 +3,12 @@ import { useShallowEffect } from "@mantine/hooks";
|
||||
import { cookies } from "next/headers";
|
||||
import { useRouter } from "next/navigation";
|
||||
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() {
|
||||
const c = cookies().get("ssn");
|
||||
@@ -11,14 +16,12 @@ export default async function PageSplash() {
|
||||
? null
|
||||
: JSON.parse(
|
||||
await unsealData(c.value as string, {
|
||||
password: process.env.PWD as string,
|
||||
password: (await getConfig()).server.password,
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<SplashScreen data={tkn} />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -92,6 +92,7 @@ export default function Validasi() {
|
||||
color="green"
|
||||
onClick={() => {
|
||||
onValid();
|
||||
// myConsole("ok")
|
||||
}}
|
||||
>
|
||||
Submit
|
||||
|
||||
@@ -5,12 +5,18 @@ import { getConfig } from "@/bin/config";
|
||||
import { unsealData } from "iron-session";
|
||||
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() {
|
||||
const c = cookies().get("ssn");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function HomeView() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<pre>{JSON.stringify(token, null, 2)}</pre>
|
||||
{/* <pre>{JSON.stringify(token, null, 2)}</pre> */}
|
||||
<Title>Home</Title>
|
||||
<Text>Welcome, {token?.username}</Text>
|
||||
<Logout />
|
||||
|
||||
Reference in New Issue
Block a user