From d46bf56209ca250fc4108af46375359652ba7fd8 Mon Sep 17 00:00:00 2001 From: physcik Date: Mon, 20 Apr 2026 21:52:20 +0500 Subject: Cleanup --- backend/src/API/AuthenticationAPI.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'backend/src/API') diff --git a/backend/src/API/AuthenticationAPI.zig b/backend/src/API/AuthenticationAPI.zig index 9b45ff4..80988aa 100644 --- a/backend/src/API/AuthenticationAPI.zig +++ b/backend/src/API/AuthenticationAPI.zig @@ -7,10 +7,22 @@ const Handler = @import("../Handler.zig"); const Tokens = @import("../Authentication/Tokens.zig"); pub fn RegisterEndpoints(router: *httpz.Router(*Handler.Handler,*const fn (*Handler.RequestData, *httpz.request.Request, *httpz.response.Response) anyerror!void)) void { + router.get("/auth", getUser, .{}); router.post("/auth/register", register, .{}); router.post("/auth/login", login, .{}); } +fn getUser(data: *Handler.RequestData, _: *httpz.Request, res: *httpz.Response) !void { + if (data.User == null) { + try res.json(.{.status = "Unauthnticated"}, .{}); + return; + } + try res.json(.{ + .Username = data.User.?.Username, + .Role = data.User.?.Role, + }, .{}); +} + fn register(_: *Handler.RequestData, req: *httpz.Request, res: *httpz.Response) !void { var body = try req.json(model.RequestBody) orelse { res.setStatus(.bad_request); -- cgit v1.3