stytch_client

This package wraps the Stytch authentication service in type-safe
Gleam code. It is meant to be used in your backend to authenticate users.
At the moment, only magic link and passcode auth are supported.
There are examples showing a complete full stack lustre
application working with this package on Wisp backend and several alternative client setups..
You’ll need the stytch_codecs package from the monorepo to use this package.
It contains shared types and encoders that you will likely want to use in your UI.
Steps to set up authentication (magic link)
- Sign up for Stytch
- Create a backend for your gleam repository (e.g.
wisp) Follow Lustre Full Stack
Guide if you
need assistance.
- Add a
.env file with three keys:
- SECRET_KEY_BASE: random 64 character string (e.g. from
wisp.random_string)
- STYTCH_PROJECT_ID: from Stytch dashboard
- STYTCH_SECRET: from Stytch dashboard
- Add routes for
send_sign_in_link, authenticate, me, and sign_out
using session token authentication. JWT might work; I haven’t tested yet.
Submit a PR updating this bullet if you do!
- For each route (See example routes):
- Decode json payload
- Construct a Stytch client
- Call the appropriate function in stytch_client
- Process the response, handling errors appropriately
- Return appropriate response to frontend.
- Create a frontend for your gleam repository, probably using Lustre.
- Hook up auth model and views as shown in examples.
- Do something with those unstyled auth views.
- Run
gleam run -m lustre/dev build --outdir=../server/priv/static in
client package.
- Run
gleam run in server package.
Passcode auth is similar, but you’ll need slightly different routes.