From e293a40d6bb62e4fa8cc212fcc8bb4b3501da287 Mon Sep 17 00:00:00 2001 From: physcik Date: Fri, 17 Apr 2026 23:11:33 +0500 Subject: Sesstion token generation + storage --- backend/src/API/AuthenticationAPI.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'backend/src/API/AuthenticationAPI.zig') diff --git a/backend/src/API/AuthenticationAPI.zig b/backend/src/API/AuthenticationAPI.zig index af3a975..a792e33 100644 --- a/backend/src/API/AuthenticationAPI.zig +++ b/backend/src/API/AuthenticationAPI.zig @@ -4,6 +4,7 @@ const model = @import("../Models/User.zig"); const db = @import("../Database/Connection.zig"); const errDesc = @import("ErrorDescription.zig"); const Handler = @import("../Handler.zig"); +const Tokens = @import("../Authentication/Tokens.zig"); pub fn RegisterEndpoints(router: *httpz.Router(*Handler.Handler,*const fn (*Handler.Handler, *httpz.request.Request, *httpz.response.Response) anyerror!void)) void { router.post("/auth/register", register, .{}); @@ -39,7 +40,7 @@ fn login(_: *Handler.Handler, req: *httpz.Request, res: *httpz.Response) !void { const username = body.Username; const pwd = body.Password; - _ = db.Users.GetByCredentials(req.arena, username, pwd) catch |err| { + const user = db.Users.GetByCredentials(req.arena, username, pwd) catch |err| { if (err == db.ResultErrors.NotFound) { res.setStatus(.unauthorized); try res.json(errDesc.ErrorDescriptor { @@ -50,5 +51,8 @@ fn login(_: *Handler.Handler, req: *httpz.Request, res: *httpz.Response) !void { return err; }; + const token = try Tokens.GenerateNewSession(res.arena, user); + try res.json(.{ .Token = token } , .{}); + // TODO: add token here } -- cgit v1.3