···2828 just client::deps-update
2929 just server::deps-update
30303131+# Check for errors
3132[group("dev")]
3233lint:
3333- just shared::lint
3434- just client::lint
3534 just server::lint
3535+ just client::lint
3636+ just shared::lint
36373838+# Run unit tests
3739[group("dev")]
3840test:
3941 just server::test
···4848 |> pog.execute(db)
4949}
50505151-/// A row you get from running the `whoami` query
5252-/// defined in `./src/server/auth/sql/whoami.sql`.
5353-///
5454-/// > ๐ฟ๏ธ This type definition was generated automatically using v4.6.0 of the
5555-/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
5656-///
5757-pub type WhoamiRow {
5858- WhoamiRow(id: Uuid, full_name: String, email: String, phone: String)
5959-}
6060-6161-/// Runs the `whoami` query
6262-/// defined in `./src/server/auth/sql/whoami.sql`.
6363-///
6464-/// > ๐ฟ๏ธ This function was generated automatically using v4.6.0 of
6565-/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
6666-///
6767-pub fn whoami(
6868- db: pog.Connection,
6969- arg_1: Uuid,
7070-) -> Result(pog.Returned(WhoamiRow), pog.QueryError) {
7171- let decoder = {
7272- use id <- decode.field(0, uuid_decoder())
7373- use full_name <- decode.field(1, decode.string)
7474- use email <- decode.field(2, decode.string)
7575- use phone <- decode.field(3, decode.string)
7676- decode.success(WhoamiRow(id:, full_name:, email:, phone:))
7777- }
7878-7979- "select u.id, u.full_name, u.email, u.phone
8080-from public.user_account as u
8181-where u.id = $1;
8282-"
8383- |> pog.query
8484- |> pog.parameter(pog.text(uuid.to_string(arg_1)))
8585- |> pog.returning(decoder)
8686- |> pog.execute(db)
8787-}
8888-8951// --- Encoding/decoding utils -------------------------------------------------
90529153/// A decoder to decode `Uuid`s coming from a Postgres query.
-3
server/src/server/auth/sql/whoami.sql
···11-select u.id, u.full_name, u.email, u.phone
22-from public.user_account as u
33-where u.id = $1;
+10-2
server/src/server/router/login.gleam
···88import server/auth
99import server/context.{type Context}
1010import shared/session
1111+import shared/user
1112import wisp.{type Request, type Response}
1213import youid/uuid
13141415type LoginError {
1516 Auth(auth.AuthError)
1717+ QueryError(user.UserError)
1618}
17191820/// ๎ธฌ Queries the database and store a session token containing the user uuid
···4446) -> Response {
4547 let query_result = {
4648 use user <- result.map(
4747- auth.whoami(db, user_uuid)
4848- |> result.map_error(Auth),
4949+ user.find(db, user_uuid)
5050+ |> result.map_error(QueryError),
4951 )
50525153 session.Authenticated(user)
···7274fn handle_error(err: LoginError) -> Response {
7375 case err {
7476 Auth(err) -> auth.handle_error(err)
7777+7878+ QueryError(err) ->
7979+ case err {
8080+ user.NotFound -> wisp.not_found()
8181+ user.Database(_) -> wisp.internal_server_error()
8282+ }
7583 }
7684}
7785
···11+//// This module contains the code to run the sql queries defined in
22+//// `./src/shared/user/sql`.
33+//// > ๐ฟ๏ธ This module was generated automatically using v4.6.0 of
44+//// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
55+////
66+77+import gleam/dynamic/decode
88+import pog
99+import youid/uuid.{type Uuid}
1010+1111+/// A row you get from running the `find_by_id` query
1212+/// defined in `./src/shared/user/sql/find_by_id.sql`.
1313+///
1414+/// > ๐ฟ๏ธ This type definition was generated automatically using v4.6.0 of the
1515+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
1616+///
1717+pub type FindByIdRow {
1818+ FindByIdRow(id: Uuid, full_name: String, email: String, phone: String)
1919+}
2020+2121+/// Runs the `find_by_id` query
2222+/// defined in `./src/shared/user/sql/find_by_id.sql`.
2323+///
2424+/// > ๐ฟ๏ธ This function was generated automatically using v4.6.0 of
2525+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
2626+///
2727+pub fn find_by_id(
2828+ db: pog.Connection,
2929+ arg_1: Uuid,
3030+) -> Result(pog.Returned(FindByIdRow), pog.QueryError) {
3131+ let decoder = {
3232+ use id <- decode.field(0, uuid_decoder())
3333+ use full_name <- decode.field(1, decode.string)
3434+ use email <- decode.field(2, decode.string)
3535+ use phone <- decode.field(3, decode.string)
3636+ decode.success(FindByIdRow(id:, full_name:, email:, phone:))
3737+ }
3838+3939+ "select
4040+ u.id,
4141+ u.full_name,
4242+ u.email,
4343+ u.phone
4444+from public.user_account as u
4545+where u.id =
4646+$1;
4747+"
4848+ |> pog.query
4949+ |> pog.parameter(pog.text(uuid.to_string(arg_1)))
5050+ |> pog.returning(decoder)
5151+ |> pog.execute(db)
5252+}
5353+5454+// --- Encoding/decoding utils -------------------------------------------------
5555+5656+/// A decoder to decode `Uuid`s coming from a Postgres query.
5757+///
5858+fn uuid_decoder() {
5959+ use bit_array <- decode.then(decode.bit_array)
6060+ case uuid.from_bit_array(bit_array) {
6161+ Ok(uuid) -> decode.success(uuid)
6262+ Error(_) -> decode.failure(uuid.v7(), "Uuid")
6363+ }
6464+}
+8
shared/src/shared/user/sql/find_by_id.sql
···11+select
22+ u.id,
33+ u.full_name,
44+ u.email,
55+ u.phone
66+from public.user_account as u
77+where u.id =
88+$1;