zynagent-first application framework

Back to the API reference

zyn.GuardDecision#

/// The result of evaluating a route guard.
pub const GuardDecision = union(enum) {
    allow,
    unauthenticated,
    forbidden,
    not_found,
    redirect_response: Redirect,
    challenge_response: Challenge,

    pub const Redirect = struct {
        status: std.http.Status,
        location: []const u8,
    };

    pub const Challenge = union(enum) {
        basic: Response.BasicChallengeOptions,
        bearer: Response.BearerChallengeOptions,
    };

    /// Requests a terminal redirect which owns `location` when evaluated.
    pub fn redirect(status: std.http.Status, location: []const u8) GuardDecision;

    /// Requests a terminal 401 response with a typed authentication challenge.
    pub fn challenge(
        comptime scheme: Response.ChallengeScheme,
        options: switch (scheme) {
            .basic => Response.BasicChallengeOptions,
            .bearer => Response.BearerChallengeOptions,
        },
    ) GuardDecision;
};