Signing in and out
Save a new session, end it in every tab, and revoke the ended tokens on your backend.
auth.signIn({ accessToken, refreshToken?, expiresIn?, user }) validates and
saves a new session, replacing any current one. 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 once the user is already signed out.
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 (${.})`);
};A failed revocation is reported in state.error as REVOKE_FAILED without
undoing the sign-out: the user asked to leave, and has. The client doesn't
revoke a session the backend already rejected.