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"),
|
||||
});
|
||||
34
app/api/products/route.tsx
Normal file
34
app/api/products/route.tsx
Normal 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})
|
||||
|
||||
// }
|
||||
10
app/api/products/schema.ts
Normal file
10
app/api/products/schema.ts
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"),
|
||||
// });
|
||||
15
app/api/user/[id]/route.tsx
Normal file
15
app/api/user/[id]/route.tsx
Normal 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
26
app/api/user/route.tsx
Normal 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})
|
||||
// }
|
||||
Reference in New Issue
Block a user