this repo has no description
lustre
frontent
oat-ui
gleam
1import client/route
2import client/session/token
3import gleam/dynamic/decode
4
5pub type Session {
6 /// User is sucessfully authenticated and is allowed to
7 /// access protected routes.
8 Authenticated(token.Token)
9 /// User is waiting for the Server to validate their credentials
10 /// and will be redirected on success / failure.
11 Pending(on_success: route.Route, on_error: route.Route)
12
13 /// User is not authenticated and can only access public routes
14 Guest
15}
16
17pub fn decoder() -> decode.Decoder(Session) {
18 use variant <- decode.field("type", decode.string)
19
20 case variant {
21 "authenticated" -> {
22 use token <- decode.field("token", token.decoder())
23 decode.success(Authenticated(token))
24 }
25
26 "pending" -> {
27 use on_success <- decode.field("on_success", route.decoder())
28 use on_error <- decode.field("on_error", route.decoder())
29 decode.success(Pending(on_success:, on_error:))
30 }
31
32 "guest" -> decode.success(Guest)
33 _ -> decode.failure(Guest, "Session")
34 }
35}