Skip to Content
Using the client

Signing in and out

Save a new session, end it in every tab, and revoke the ended tokens on your backend.

auth.signIn({ ...tokens, user }) validates and saves a new session, replacing any current one, even a locked one. With fromAccessToken, leave out user. The latest call wins, and invalid input keeps the previous session. Expiry covers how the token's lifetime is found.

auth.signOut() ends the session and clears storage. Other tabs sign out too when the storage reports changes, as webStorage() does, and locking is off.

If your backend can revoke tokens, give the client a revoke callback. It receives the ended tokens after the user is signed out:

src/revoke.ts
import type {  } from "@monarcode/session-kit";

/** Pass as `createAuth`'s `revoke` option. */
export const :  = async ({ ,  }) => {
  if (!) return;
  const  = await ("https://api.example.com/auth/revoke", {
    : "POST",
    ,
    : { "Content-Type": "application/json" },
    : .({  }),
  });
  if (!.) throw new (`Revoke failed (${.})`);
};

signOut() resolves once revoke settles, so await it before a full-page redirect, which would cancel the request.

A failed revocation shows in state.error as REVOKE_FAILED, and the sign-out stands. The user asked to leave, and has. The client doesn't revoke a session the backend already rejected.