edit:module:user | add middlewware for unauthenticated only

This commit is contained in:
2025-06-22 09:45:06 +07:00
parent fbd5b68b10
commit 48946be6b7
3 changed files with 11 additions and 23 deletions

View File

@ -3,13 +3,12 @@ import { getCookie } from "../../helpers/http/userHeader/cookies/getCookies";
import { returnErrorResponse } from "../../helpers/callback/httpResponse";
export const unautenticatedMiddleware = (ctx: Context) => {
// Check if the user is already logged in by checking the auth token in cookies. If the user is logged in, return an error response
try {
const cookies = getCookie(ctx);
if (cookies.auth_token)
return returnErrorResponse(ctx.set, 403, "User already aunthenticated");
// pass
} catch (error) {
// pass
const cookie = getCookie(ctx);
if (cookie && cookie.auth_token)
return returnErrorResponse(ctx.set, 401, "You are already logged in. ");
} catch (_) {
// Pass
}
};