diff --git a/src/api/auth/auth.route.ts b/src/api/auth/auth.route.ts index a46b7f7..ab00a43 100644 --- a/src/api/auth/auth.route.ts +++ b/src/api/auth/auth.route.ts @@ -3,45 +3,58 @@ import { generateToken, getUserData, updateUser } from "./auth.controller"; import { verifyAuth } from "../../middlewares/auth.middlewares"; export const authRoute = new Elysia({ - prefix: "/auth", - tags: ["Auth"], - detail: { - description: "Routes for managing users", - } -}) - -authRoute.get("/user/:userId", async ({ params: { userId } }) => await getUserData(userId), { - params: t.Object({ - userId: t.String() - }) + prefix: "/api/auth", + tags: ["Auth"], + detail: { + description: "Routes for managing users", + }, }); -authRoute.post("/user/update/:userId", async ({ params: { userId }, body }) => await updateUser(userId, body), { +authRoute.get( + "/user/:userId", + async ({ params: { userId } }) => await getUserData(userId), + { params: t.Object({ - userId: t.String() + userId: t.String(), + }), + } +); + +authRoute.post( + "/user/update/:userId", + async ({ params: { userId }, body }) => await updateUser(userId, body), + { + params: t.Object({ + userId: t.String(), }), body: t.Object({ - paid_status: t.String(), - package_expire_date: t.String(), - }) -}); + paid_status: t.String(), + package_expire_date: t.String(), + }), + } +); -authRoute.get("/generate-token/:userId", async (context) => await generateToken(context)); +authRoute.get( + "/generate-token/:userId", + async (context) => await generateToken(context) +); authRoute.get("/user/me", async ({ cookie }) => { - const authData = await verifyAuth(cookie); - if (authData.status !== 200) { - return authData; + const authData = await verifyAuth(cookie); + if (authData.status !== 200) { + return authData; + } else { + const userId: string | any = authData.userId; + const response = await getUserData(userId); + if (response?.status === 200) { + return { + ...response.data, + token: authData.token, + status: 200, + message: "User data fetched successfully", + }; + } else { + return response; } - else { - const userId: string | any = authData.userId; - const response = await getUserData(userId); - if (response?.status === 200) { - return { ...response.data, token: authData.token, status: 200, message: "User data fetched successfully" }; - } - else { - return response; - } - } -}) - + } +}); diff --git a/src/app.ts b/src/app.ts index 7824052..a30e148 100644 --- a/src/app.ts +++ b/src/app.ts @@ -58,16 +58,20 @@ const app = new Elysia({ console.error(error); }); -// all routes here -app.use(api); +const api = app.group("/api", (app) => { + app.get("/", () => "API root is working"); -// Debug - Print all registered routes -console.log("All registered routes:"); -app.routes.forEach((route) => { - console.log(`${route.method} ${route.path}`); + // Include all your other routes inside this group + app.use(authRoute); + app.use(projectRoutes); + app.use(uploadRoutes); + app.use(downloadRoute); + + return app; }); -app.get("/", () => "API root is working"); +// all routes here +app.use(api); app.listen(ENV.SERVER_PORT, () => { console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);