rewrite jwt set in login service

This commit is contained in:
rafiarrafif
2025-05-12 21:58:13 +07:00
parent ed8840ee1f
commit c72a06adb4
10 changed files with 9 additions and 25 deletions

View File

@ -4,23 +4,6 @@ import { JWTAuthToken } from "./types";
import { parse } from "cookie";
import { returnErrorResponse } from "../../../callback/httpResponse";
/**
* Verifies the authentication cookie from the request header.
*
* This helper function is used in an ElysiaJS context to check the validity of
* a user's authentication token stored in cookies. If the cookie is not found,
* it returns a `400 Bad Request`. If the token is invalid or expired, it returns
* a `401 Unauthorized`. If the token is valid, it returns the decoded user data.
*
* @param ctx - The request context from Elysia, used to read headers and set the response.
*
* @returns The decoded JWT payload if the token is valid,
* or a standardized error response if the cookie is missing or invalid.
*
* @example
* const decodedToken = decodeAuthToken(ctx);
* ctx => Elysia context
*/
export const JWTDecodeToken = (ctx: Context): JWTAuthToken => {
const cookiePayload = ctx.request.headers.get("Cookie");
if (!cookiePayload)