summaryrefslogtreecommitdiff
path: root/backend/src/Authentication
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/Authentication')
-rw-r--r--backend/src/Authentication/Tokens.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/backend/src/Authentication/Tokens.zig b/backend/src/Authentication/Tokens.zig
index 6548ce7..37bfd5a 100644
--- a/backend/src/Authentication/Tokens.zig
+++ b/backend/src/Authentication/Tokens.zig
@@ -20,6 +20,9 @@ pub fn Init() !void {
fn generateSessionToken(buf: []u8) []u8 {
for (0..64) |i| {
buf[i] = std.Random.intRangeAtMost(rnd, u8, 'A', 'z');
+ if (buf[i] == '\\') {
+ buf[i] = '@';
+ }
}
return buf;
}
@@ -40,3 +43,19 @@ pub fn GenerateNewSession(allocator: std.mem.Allocator, user: userModel.User) ![
return newToken;
}
+
+pub fn GetUserFromToken(allocator: std.mem.Allocator, token: []const u8) !?std.json.Parsed(userModel.User) {
+ const saved = try redis.ReadFromTopic(allocator, topicName, token) orelse {
+ std.debug.print("The token was not found \n", .{});
+ return null;
+ };
+ std.debug.print("FromRedis: {s}\n", .{ saved });
+ const parsed = try std.json.parseFromSlice(
+ userModel.User,
+ allocator,
+ saved,
+ .{
+ .ignore_unknown_fields = true,
+ });
+ return parsed;
+}