summaryrefslogtreecommitdiff
path: root/backend/src/Handler.zig
diff options
context:
space:
mode:
authorphyscik <mynameisgennadiy@vk.com>2026-04-28 12:34:36 +0500
committerphyscik <mynameisgennadiy@vk.com>2026-04-28 12:34:36 +0500
commitec5ef35ed47b90b9f09199d28f7885f8287815a8 (patch)
tree5231f94716e2d3a9dae618cba9bd83534dca43c1 /backend/src/Handler.zig
parent9a43fa05ade031c91d515d1254e05fd33cc7a482 (diff)
description frontend
Diffstat (limited to 'backend/src/Handler.zig')
-rw-r--r--backend/src/Handler.zig14
1 files changed, 8 insertions, 6 deletions
diff --git a/backend/src/Handler.zig b/backend/src/Handler.zig
index 2f3389e..1da0d42 100644
--- a/backend/src/Handler.zig
+++ b/backend/src/Handler.zig
@@ -3,7 +3,7 @@ const httpz = @import("httpz");
const userModel = @import("Models/User.zig");
const tokens = @import("Authentication/Tokens.zig");
-pub const errors = error {
+pub const authError = error {
Unauthorized,
Forbidden,
};
@@ -38,10 +38,12 @@ pub const RequestData = struct {
return self.User.?.Role >= minimalRole;
}
- pub fn CheckAccess(self: RequestData, minimalRole: userModel.Role) !void {
- if (self.User == null) return errors.Unauthorized;
+ /// This function returns an error that is caught by a handler. Add this to
+ /// the start of the handler to add an auth
+ pub fn CheckAccess(self: RequestData, minimalRole: userModel.Role) authError!void {
+ if (self.User == null) return authError.Unauthorized;
if (@intFromEnum(self.User.?.Role) < @intFromEnum(minimalRole))
- return errors.Forbidden;
+ return authError.Forbidden;
}
};
@@ -51,10 +53,10 @@ pub const Handler = struct {
// std.debug.print("Data: {any}\n", .{ data });
action(&data, req, res) catch |err| {
switch (err) {
- errors.Forbidden => {
+ authError.Forbidden => {
res.setStatus(.forbidden);
},
- errors.Unauthorized => {
+ authError.Unauthorized => {
res.setStatus(.unauthorized);
},
else => {