ServerAuthSession
Constructors
Constructor
new ServerAuthSession(config): ServerAuthSession;
Parameters
| Parameter | Type |
|---|---|
config | ServerAuthSessionConfig |
Returns
ServerAuthSession
Methods
getToken()
getToken(): Promise<string | null>;
The access token to authenticate SSR requests with. Returns the cookie's
token when it is still comfortably valid; otherwise refreshes (rotating the
refresh token and rewriting both cookies). null means no usable session.
Returns
Promise<string | null>
refresh()
refresh(): Promise<
| {
kind: "rotated";
tokens: {
accessToken: string;
refreshToken: string;
refreshTokenExpiresAt: number;
userId: string;
};
}
| {
kind: "noSession";
}>;
Force a refresh from the refresh-token cookie, updating the cookies to match the outcome:
rotated: rewrite both cookies with the new bundle.noSession: clear both.
Returns
Promise<
| {
kind: "rotated";
tokens: {
accessToken: string;
refreshToken: string;
refreshTokenExpiresAt: number;
userId: string;
};
}
| {
kind: "noSession";
}>
setTokens()
setTokens(bundle): Promise<void>;
Persist a token bundle as cookies. Used after a sign-in whose bundle was minted elsewhere (e.g. a client-side sign-in flow) to move the refresh token into the httpOnly cookie. Both cookies live as long as the refresh token; the access token is refreshed on expiry via getToken.
Parameters
| Parameter | Type |
|---|---|
bundle | { accessToken: string; refreshToken: string; refreshTokenExpiresAt: number; userId: string; } |
bundle.accessToken | string |
bundle.refreshToken | string |
bundle.refreshTokenExpiresAt | number |
bundle.userId | string |
Returns
Promise<void>