edit:module:user | add middlewware for unauthenticated only
This commit is contained in:
@ -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
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user