upd: login
Deskripsi: - pembaruan login - batasan login No Issues
This commit is contained in:
17
src/app/(application)/layout.tsx
Normal file
17
src/app/(application)/layout.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { pwd_key_config } from "@/module/_global"
|
||||
import { funDetectCookies } from "@/module/auth"
|
||||
import { unsealData } from "iron-session"
|
||||
import _ from "lodash"
|
||||
import { cookies } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
export default async function Layout({ children }: { children: React.ReactNode }) {
|
||||
const cookies = await funDetectCookies()
|
||||
if (!cookies) return redirect('/')
|
||||
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
import { ViewLogin } from "@/module/auth";
|
||||
import { Box, Image, rem, Stack, Text } from "@mantine/core";
|
||||
import { pwd_key_config } from "@/module/_global";
|
||||
import { funDetectCookies, ViewLogin } from "@/module/auth";
|
||||
import { unsealData } from "iron-session";
|
||||
import _ from "lodash";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Home() {
|
||||
export default async function Home() {
|
||||
const cookies = await funDetectCookies()
|
||||
if (cookies) return redirect('/home')
|
||||
return (
|
||||
<>
|
||||
<ViewLogin/>
|
||||
<ViewLogin />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user