complete middleware
This commit is contained in:
@ -1,10 +1,14 @@
|
||||
import { Context } from "elysia";
|
||||
import { getCookie } from "../helpers/http/userHeader/cookies/getCookies";
|
||||
import { mainErrorHandler } from "../helpers/error/handler";
|
||||
import { returnErrorResponse } from "../helpers/callback/httpResponse";
|
||||
|
||||
export const authMiddleware = (ctx: Context) => {
|
||||
const token = ctx.cookie.auth_token;
|
||||
|
||||
if (!token) {
|
||||
ctx.set.status = 401;
|
||||
throw "Unauthorized: Token missing";
|
||||
try {
|
||||
const cookie = getCookie(ctx);
|
||||
if (!cookie.auth_token)
|
||||
return returnErrorResponse(ctx.set, 401, "User Unauthorized");
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user