second commit
This commit is contained in:
14
app/api/auth/logout/route.tsx
Normal file
14
app/api/auth/logout/route.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const response = NextResponse.redirect(new URL("/login", req.url));
|
||||
response.cookies.set("isAuth", "", {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "strict",
|
||||
path: "/",
|
||||
expires: new Date(0),
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
13
app/api/auth/route.tsx
Normal file
13
app/api/auth/route.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { username, password } = await req.json();
|
||||
|
||||
if (username === "Wdipl" && password === "Admin@123") {
|
||||
const response = NextResponse.json({ success: true });
|
||||
response.cookies.set("isAuth", "true", { httpOnly: true });
|
||||
return response;
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: false }, { status: 401 });
|
||||
}
|
||||
10
app/api/auth/schema.tsx
Normal file
10
app/api/auth/schema.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
import * as yup from "yup";
|
||||
// Validation Schema with Yup
|
||||
export const schema = yup.object({
|
||||
username: yup.string().required("Username is required"),
|
||||
password: yup
|
||||
.string()
|
||||
.min(6, "Password must be at least 6 characters")
|
||||
.required("Password is required"),
|
||||
});
|
||||
Reference in New Issue
Block a user