feat: tambah dependensi 'jose' versi 5.9.2 pada package.json
refactor: rapikan identasi dan buat field 'expires' opsional di model UserSession pada schema prisma chore: bersihkan import tidak terpakai di route login dan register API
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import { PwdCookies } from "@/app/lib";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { sealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
|
||||
export async function Auth_funRegister(data: any) {
|
||||
|
||||
export async function Auth_funRegister({
|
||||
data,
|
||||
HIPMI_PWD,
|
||||
}: {
|
||||
data: any;
|
||||
HIPMI_PWD: string;
|
||||
}) {
|
||||
const cekUsername = await prisma.user.findUnique({
|
||||
where: {
|
||||
username: data.username,
|
||||
@@ -28,21 +31,31 @@ export async function Auth_funRegister(data: any) {
|
||||
});
|
||||
if (!create) return { status: 400, message: "Gagal Mendaftar" };
|
||||
|
||||
const seal = await sealData(
|
||||
const sealToken = await sealData(
|
||||
JSON.stringify({
|
||||
id: create.id,
|
||||
username: create.username,
|
||||
}),
|
||||
{
|
||||
password: PwdCookies
|
||||
password: HIPMI_PWD,
|
||||
}
|
||||
);
|
||||
|
||||
cookies().set({
|
||||
name: "ssn",
|
||||
value: seal,
|
||||
maxAge: 60 * 60 * 24 * 7,
|
||||
value: sealToken,
|
||||
// maxAge: 60 * 60 * 24 * 7,
|
||||
});
|
||||
|
||||
const createUserSession = await prisma.userSession.create({
|
||||
data: {
|
||||
token: sealToken,
|
||||
userId: create.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!createUserSession)
|
||||
return { status: 400, message: "Gagal Membuat User Session" };
|
||||
|
||||
return { status: 200, message: "Berhasil Mendaftar" };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user