edit:module:user | add middlewware for authenticated only
This commit is contained in:
@ -64,9 +64,7 @@ export const editUserController = async (
|
||||
try {
|
||||
// Get the user JWT token from cookies, if the token is not found, return an error response
|
||||
const userCookie = getCookie(ctx);
|
||||
const auth_token = userCookie.auth_token;
|
||||
if (!auth_token)
|
||||
return returnErrorResponse(ctx.set, 401, "User Unauthenticated");
|
||||
const auth_token = userCookie.auth_token!;
|
||||
|
||||
// Get user browser header information from the context
|
||||
const userHeaderInfo = getUserHeaderInformation(ctx);
|
||||
|
||||
@ -3,10 +3,13 @@ import { getAllUserController } from "./controller/getAllUser.controller";
|
||||
import { createUserController } from "./controller/createUser.controller";
|
||||
import { editUserController } from "./controller/editUser.controller";
|
||||
import { unautenticatedMiddleware } from "../../middleware/auth/unauthenticated.middleware";
|
||||
import { authenticatedMiddleware } from "../../middleware/auth/authenticated.middleware";
|
||||
|
||||
export const userModule = new Elysia({ prefix: "/users" })
|
||||
.get("/", getAllUserController)
|
||||
.put("/", editUserController)
|
||||
.group("", (app) =>
|
||||
app.onBeforeHandle(unautenticatedMiddleware).post("/", createUserController)
|
||||
)
|
||||
.group("", (app) =>
|
||||
app.onBeforeHandle(authenticatedMiddleware).put("/", editUserController)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user