libduvet/http/session

Types

The client’s tokens, and the session’s single-flight renewal: whatever fails with a 401 asks here, and only the first call refreshes.

pub opaque type Session

Values

pub fn clear(session: Session) -> Nil
pub fn refresh(
  session: Session,
) -> Result(sign_in.SignIn, error.DuvetError)

Rotates the session’s tokens, as refreshSession does in the Dart client.

pub fn renew(
  session: Session,
  sent_token: String,
) -> Result(Nil, error.DuvetError)

Refreshes the tokens when [sent_token] is still the one in use; when it isn’t, a renewal already happened and nothing is done. Answers whether the request may be sent again.

pub fn session_token(session: Session) -> String
pub fn set_tokens(
  session: Session,
  token: String,
  session_token: String,
) -> Nil

Keeps a login’s tokens. A session token that comes back empty keeps the one there was, as the Dart client does.

pub fn start(
  transport: fn(transport.Request, fn(Int) -> Nil, fn() -> Nil) -> Result(
    transport.Response,
    transport.ExchangeError,
  ),
  router: api_router.ApiRouter,
  token: String,
  session_token: String,
  timeout_ms: Int,
) -> Session

Starts the session store, resuming the tokens of a session started before.

pub fn token(session: Session) -> String
pub fn tokens(session: Session) -> #(String, String)
✨ Search Document