stytch_client

Types

Configured stytch client to connect to the stytch service.

The client secret should likely come from an environment variable; it needs to be protected.

pub opaque type StytchClient

Various error types that may occur while processing Stytch responses

pub type StytchError {
  HttpcError(httpc.HttpError)
  DecodeError(decode.DecodeError)
  JsonError(json.DecodeError)
  ClientError(stytch_codecs.StytchClientError)
}

Constructors

Values

pub fn magic_link_authenticate(
  client: StytchClient,
  token: String,
  session_duration_minutes: Int,
) -> Result(stytch_codecs.AuthenticateResponse, StytchError)

Authenticate a token returned from Stytch during a magic link redirect flow.

pub fn magic_link_login_or_create(
  client: StytchClient,
  email: String,
) -> Result(stytch_codecs.LoginOrCreateResponse, StytchError)

Send a magic link to the (typically user-provided) e-mail address.

This works whether or not the user has previously logged in.

pub fn new(project_id: String, secret: String) -> StytchClient

Consturct a new StytchClient given a projcet_id and sercet. Stytch encodes the environment in the project_id so we can connect to the correct service when it is called

pub fn passcode_authenticate(
  client: StytchClient,
  code: String,
  method_id: String,
  session_duration_minutes: Int,
) -> Result(stytch_codecs.AuthenticateResponse, StytchError)

Authenticate the passcode the user entered and pass it to stytch client.

pub fn passcode_login_or_create(
  client: StytchClient,
  email: String,
) -> Result(stytch_codecs.LoginOrCreateResponse, StytchError)

Create or log in a user using passcode authentication.

Arguably more secure than magic link auth as it avoids sending an un-verified e-mail to the user.

pub fn session_authenticate(
  client: StytchClient,
  token: String,
  session_duration_minutes: Int,
) -> Result(
  stytch_codecs.SessionAuthenticateResponse,
  StytchError,
)

Authenticate a session token previously returned from a passcode or magic link authentication flow.

pub fn session_revoke(
  client: StytchClient,
  token: String,
) -> Result(stytch_codecs.SessionRevokeResponse, StytchError)

Revoke a session token so it can’t be used to sign in again.

Used for signing a user out.

Search Document