Added cookie set on login
This commit is contained in:
parent
245927d75b
commit
ad8f465a4f
|
|
@ -3,29 +3,30 @@ import handleCatchApi from "@/core/utils/handleCatchApi";
|
|||
import AuthError from "@/modules/auth/error/AuthError";
|
||||
import signInSchema from "@/modules/auth/formSchemas/signInSchema";
|
||||
import signIn from "@/modules/auth/services/signIn";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
applicationJsonOnly(request.headers)
|
||||
applicationJsonOnly(request.headers);
|
||||
const data = signInSchema.safeParse(await request.json());
|
||||
|
||||
if (!data.success) {
|
||||
throw new AuthError({
|
||||
errorCode: "INVALID_CREDENTIALS",
|
||||
message: "Email or Password does not match",
|
||||
statusCode: 401
|
||||
})
|
||||
statusCode: 401,
|
||||
});
|
||||
}
|
||||
|
||||
const result = await signIn(data.data)
|
||||
const result = await signIn(data.data);
|
||||
|
||||
request.cookies.set("token", result.token)
|
||||
cookies().set("token", result.token);
|
||||
|
||||
return NextResponse.json(result);
|
||||
} catch (e) {
|
||||
return handleCatchApi(e)
|
||||
return handleCatchApi(e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user