import client/route import client/session/token import gleam/dynamic/decode pub type Session { ///  User is sucessfully authenticated and is allowed to /// access protected routes. Authenticated(token.Token) ///  User is waiting for the Server to validate their credentials /// and will be redirected on success / failure. Pending(on_success: route.Route, on_error: route.Route) ///  User is not authenticated and can only access public routes Guest } pub fn decoder() -> decode.Decoder(Session) { use variant <- decode.field("type", decode.string) case variant { "authenticated" -> { use token <- decode.field("token", token.decoder()) decode.success(Authenticated(token)) } "pending" -> { use on_success <- decode.field("on_success", route.decoder()) use on_error <- decode.field("on_error", route.decoder()) decode.success(Pending(on_success:, on_error:)) } "guest" -> decode.success(Guest) _ -> decode.failure(Guest, "Session") } }