Keeps the user signed in across reloads and tabs, in one localStorage entry
every tab shares. AuthProvider and useAuth are its only users.
Forgets the stored session, but only if it still holds token. Another tab
may have replaced it with fresh tokens from a password change, and a 401 for
the old token here must not wipe those.
Checks whether token, a JWT, has expired, without asking the server. An
unreadable one counts as expired.
Returns the stored session, or null. A session that is unreadable, expired or from before roles existed is removed from storage.
Stores session, for every tab.
& { mediaToken?: string; settings?: UserSettings; }
Held by AuthProvider and stored here. It is the AuthResponse of a
sign-in or sign-up, except that one stored before media tokens existed has
none until AuthProvider fetches it. AuthProvider adds the user's
settings once it has read them from the server, and useSettings keeps
them current.
The localStorage key of the session. AuthProvider listens for changes to it
from other tabs.
Usage
import * as mod from "src/utils/auth/storage.ts";