upd: login
Deskripsi: - pembaruan login - batasan login No Issues
This commit is contained in:
@@ -3,7 +3,7 @@ import { unsealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function GET() {
|
||||
const sessionCookie = cookies().get("sessionCookie");
|
||||
const sessionCookie = cookies().get("sessionCookieSDM");
|
||||
const userId = await unsealData(sessionCookie!.value, {
|
||||
password: pwd_key_config,
|
||||
});
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
|
||||
import { prisma } from "@/module/_global";
|
||||
import { ILogin } from "@/types";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { phone }: ILogin = await req.json();
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { phone, isActive: true },
|
||||
select: { id: true, phone: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: "Email atau Password salah",
|
||||
try {
|
||||
const { phone }: ILogin = await req.json();
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { phone, isActive: true },
|
||||
select: { id: true, phone: true },
|
||||
});
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
success: true,
|
||||
message: "Login Berhasil",
|
||||
phone: user.phone,
|
||||
id: user.id,
|
||||
});
|
||||
if (!user) {
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: "Nomor telepon tidak terdaftar",
|
||||
});
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
success: true,
|
||||
message: "Sukses",
|
||||
phone: user.phone,
|
||||
id: user.id,
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return Response.json({ message: "Internal Server Error", success: false });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function DELETE() {
|
||||
cookies().delete('sessionCookie')
|
||||
cookies().delete('sessionCookieSDM')
|
||||
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { pwd_key_config } from "@/module/_global";
|
||||
import { sealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { user } = await req.json();
|
||||
const encryptedUserData = await sealData(user, { password: pwd_key_config });
|
||||
|
||||
cookies().set({
|
||||
name: "sessionCookie",
|
||||
value: encryptedUserData,
|
||||
});
|
||||
|
||||
return Response.json({ success: true });
|
||||
}
|
||||
Reference in New Issue
Block a user