diff options
| author | physcik <mynameisgennadiy@vk.com> | 2026-04-17 23:11:33 +0500 |
|---|---|---|
| committer | physcik <mynameisgennadiy@vk.com> | 2026-04-17 23:11:33 +0500 |
| commit | e293a40d6bb62e4fa8cc212fcc8bb4b3501da287 (patch) | |
| tree | f0da17a7292dbfd8aa5722f9cbd774f9ad2f9e23 /backend/src/API/AuthenticationAPI.zig | |
| parent | c03658c1b5a8dad87f4b11d1b48f2c057ac3a439 (diff) | |
Sesstion token generation + storage
Diffstat (limited to 'backend/src/API/AuthenticationAPI.zig')
| -rw-r--r-- | backend/src/API/AuthenticationAPI.zig | 6 |
1 files changed, 5 insertions, 1 deletions
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 } |
