diff options
Diffstat (limited to 'backend/src/API')
| -rw-r--r-- | backend/src/API/AuthenticationAPI.zig | 12 |
1 files changed, 12 insertions, 0 deletions
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); |
