move alot to constants, fix html
Some checks failed
Code quality checks / biome (push) Failing after 12s
Some checks failed
Code quality checks / biome (push) Failing after 12s
This commit is contained in:
parent
92172479f6
commit
33a602cdd0
26 changed files with 603 additions and 296 deletions
|
@ -1,9 +1,12 @@
|
|||
import { echo } from "@atums/echo";
|
||||
import {
|
||||
errorMessages,
|
||||
httpStatus,
|
||||
successMessages,
|
||||
} from "#environment/constants";
|
||||
import { cookieService, sessionManager } from "#lib/auth";
|
||||
|
||||
import type { BaseResponse, ExtendedRequest, RouteDef } from "#types/server";
|
||||
|
||||
interface LogoutResponse extends BaseResponse {}
|
||||
import type { ExtendedRequest, LogoutResponse, RouteDef } from "#types/server";
|
||||
|
||||
const routeDef: RouteDef = {
|
||||
method: ["POST", "DELETE"],
|
||||
|
@ -17,24 +20,24 @@ async function handler(request: ExtendedRequest): Promise<Response> {
|
|||
|
||||
if (!session) {
|
||||
const response: LogoutResponse = {
|
||||
code: 401,
|
||||
code: httpStatus.UNAUTHORIZED,
|
||||
success: false,
|
||||
error: "Not authenticated",
|
||||
error: errorMessages.NOT_AUTHENTICATED,
|
||||
};
|
||||
return Response.json(response, { status: 401 });
|
||||
return Response.json(response, { status: httpStatus.UNAUTHORIZED });
|
||||
}
|
||||
|
||||
await sessionManager.invalidateSession(request);
|
||||
const clearCookie = cookieService.clearCookie();
|
||||
|
||||
const response: LogoutResponse = {
|
||||
code: 200,
|
||||
code: httpStatus.OK,
|
||||
success: true,
|
||||
message: "Logged out successfully",
|
||||
message: successMessages.LOGOUT_SUCCESSFUL,
|
||||
};
|
||||
|
||||
return Response.json(response, {
|
||||
status: 200,
|
||||
status: httpStatus.OK,
|
||||
headers: {
|
||||
"Set-Cookie": clearCookie,
|
||||
},
|
||||
|
@ -46,11 +49,13 @@ async function handler(request: ExtendedRequest): Promise<Response> {
|
|||
});
|
||||
|
||||
const response: LogoutResponse = {
|
||||
code: 500,
|
||||
code: httpStatus.INTERNAL_SERVER_ERROR,
|
||||
success: false,
|
||||
error: "Internal server error",
|
||||
error: errorMessages.INTERNAL_SERVER_ERROR,
|
||||
};
|
||||
return Response.json(response, { status: 500 });
|
||||
return Response.json(response, {
|
||||
status: httpStatus.INTERNAL_SERVER_ERROR,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue