edit:module:user | add middlewware for authenticated only

This commit is contained in:
rafiarrafif
2025-06-22 09:52:22 +07:00
parent 48946be6b7
commit 181e6f3688
3 changed files with 7 additions and 6 deletions

View File

@ -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);

View File

@ -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)
);