second commit

This commit is contained in:
2024-12-16 13:30:44 +05:30
parent b37f080da5
commit 803d521b73
41 changed files with 7242 additions and 255 deletions

View 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
View 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
View 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"),
});

View File

@@ -0,0 +1,34 @@
// import { NextRequest, NextResponse } from "next/server";
// import schema from "./schema";
// export function GET(req: NextRequest) {
// return NextResponse.json([
// {
// id: 1,
// naame: 'Milk',
// price: 2.5
// }, {
// id: 2,
// naame: 'Bread',
// price: 3.5
// },
// ])
// }
// export async function POST(req:NextRequest) {
// const body = await req.json()
// console.log(body);
// const validation = schema.safeParse(body)
// if (!validation.success)
// return NextResponse.json(validation.error.errors, {status:400})
// return NextResponse.json({id:10, name: body.name, price: body.price }, { status: 201})
// }

View 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"),
// });

View File

@@ -0,0 +1,15 @@
// import { NextRequest, NextResponse } from "next/server";
// export async function PUT(req:NextRequest, {params} : { params: { id: number}}){
// const body = await req.json()
// if(!body.name)
// return NextResponse.json({error:'Name is equied'}, { status: 400})
// if(params.id>10)
// return NextResponse.json({error:'User noty found'}, { status: 404})
// return NextResponse.json({id:1, name: body.name})
// }

26
app/api/user/route.tsx Normal file
View File

@@ -0,0 +1,26 @@
// import { NextRequest, NextResponse } from "next/server";
// export function GET(req:NextRequest){
// return NextResponse.json([
// {
// id:1,
// name: 'John'
// },
// {
// id:1,
// name:'Mosh'
// }
// ])
// }
// export async function POST(req:NextRequest){
// const body = await req.json()
// if(!body?.name)
// return NextResponse.json({error:'Name is Required'}, {status:400})
// return NextResponse.json({id:1, name: body.name})
// }