wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:recycle: use `duration` to build cookie max age

Kacaii 308ab0c9 bc0711ec

+17 -13
+17 -13
src/app/domain/user/login.gleam
··· 10 10 import argus 11 11 import formal/form 12 12 import gleam/bool 13 + import gleam/float 13 14 import gleam/http/response 14 15 import gleam/json 15 16 import gleam/list 16 17 import gleam/result 18 + import gleam/time/duration 17 19 import glight 18 20 import pog 19 21 import wisp ··· 87 89 ) -> response.Response(wisp.Body) { 88 90 case query_login_token(data:, ctx:) { 89 91 Error(err) -> handle_error(err) 90 - Ok(resp) -> set_token(data, resp, request, cookie_name) 92 + Ok(resp) -> { 93 + log_login(data) 94 + set_token(resp, request, cookie_name) 95 + } 91 96 } 92 97 } 93 98 94 99 fn set_token( 95 - data: RequestBody, 96 100 resp: LoginToken, 97 101 request: wisp.Request, 98 - cookie_name: String, 102 + cookie_name name: String, 99 103 ) -> wisp.Response { 100 - log_login(data) 101 - wisp.set_cookie( 102 - response: wisp.json_response(resp.body, 200), 103 - request: request, 104 - name: cookie_name, 105 - value: uuid.to_string(resp.user_id), 106 - security: wisp.Signed, 107 - //  Cookie lasts 1 hour in total 108 - max_age: 60 * 60, 109 - ) 104 + let response = wisp.json_response(resp.body, 200) 105 + let value = uuid.to_string(resp.user_id) 106 + let security = wisp.Signed 107 + 108 + let max_age = 109 + duration.hours(1) 110 + |> duration.to_seconds 111 + |> float.round 112 + 113 + wisp.set_cookie(response:, request:, name:, value:, security:, max_age:) 110 114 } 111 115 112 116 fn handle_error(err: LoginError) -> response.Response(wisp.Body) {