fix folder

deskripsi:
- ganti nama folder (user) ke (auth)
- hapus folder auth
This commit is contained in:
2025-02-05 15:34:06 +08:00
parent 6dc4e7afc3
commit d7252b9fb3
21 changed files with 30 additions and 102 deletions

View File

@@ -0,0 +1,22 @@
import { jwtVerify } from "jose";
export async function decrypt({
token,
encodedKey,
}: {
token: string;
encodedKey: string;
}): Promise<Record<string, any> | null> {
try {
const enc = new TextEncoder().encode(encodedKey);
const { payload } = await jwtVerify(token, enc, {
algorithms: ["HS256"],
});
return (payload.user as Record<string, any>) || null;
} catch (error) {
console.error("Gagal verifikasi session", error);
return null;
}
}
// wibu:0.2.82

View File

@@ -0,0 +1,25 @@
import { SignJWT } from "jose";
export async function encrypt({
user,
exp = "7 year",
encodedKey,
}: {
user: Record<string, any>;
exp?: string;
encodedKey: string;
}): Promise<string | null> {
try {
const enc = new TextEncoder().encode(encodedKey);
return new SignJWT({ user })
.setProtectedHeader({ alg: "HS256" })
.setIssuedAt()
.setExpirationTime(exp)
.sign(enc);
} catch (error) {
console.error("Gagal mengenkripsi", error);
return null;
}
}
// wibu:0.2.82

View File

@@ -0,0 +1,35 @@
import { cookies } from "next/headers";
import { encrypt } from "./encrypt";
export async function sessionCreate({
sessionKey,
exp = "7 year",
encodedKey,
user,
}: {
sessionKey: string;
exp?: string;
encodedKey: string;
user: Record<string, unknown>;
}) {
const token = await encrypt({
exp,
encodedKey,
user,
});
const cookie: any = {
key: sessionKey,
value: token,
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
},
};
cookies().set(cookie.key, cookie.value, { ...cookie.options });
return token;
}
// wibu:0.2.82

View File

@@ -0,0 +1,13 @@
import { Login } from "@/app_modules/auth";
import versionUpdate from "../../../../package.json";
export default async function Page() {
const version = versionUpdate.version;
return (
<>
<Login version={version} />
</>
);
}

View File

@@ -0,0 +1,5 @@
import { Register } from "@/app_modules/auth";
export default async function Page() {
return <Register />;
}

View File

@@ -0,0 +1,7 @@
import { SplashScreen } from "@/app_modules/auth";
export default async function Page() {
return <>
<SplashScreen/>
</>
}

View File

@@ -0,0 +1,5 @@
import { Validasi } from "@/app_modules/auth";
export default async function Page() {
return <Validasi />;
}

View File

@@ -0,0 +1,12 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import WaitingRoom_View from "@/app_modules/waiting_room/view";
export default async function Page() {
const userLoginId = await funGetUserIdByToken();
return (
<>
<WaitingRoom_View userLoginId={userLoginId as string} />
</>
);
}