Skip to main content

Authorization

<LayoutProvider
authProps={{
sessionResolver,
onUnauthorized, // optional
}}
authPlaceholder={AuthPlaceholder}
>
...
</LayoutProvider>

sessionResolver​

export type SessionResolver = () => Promise<Session>

A function that returns a promise that resolves to a session object.

Example

export const sessionResolver: SessionResolver = async () => {
const response = await fetch('/api/session');
const session = await response.json();
return session;
};

onUnauthorized​

export type OnUnauthorized = (reason: UnauthorizeReason) => void

A function that is called when the user is unauthorized.

ReasonDescription
sessionExpiredThe session has expired.
unauthorizedThe user is unauthorized.
logoutThe user has logged out.
loadFound unauthorize while initial load.

AuthPlaceholder​

export const AuthPlaceholder: FC = () => {
// Add your custom auth placeholder here
}

Props

NameTypeDescription
loadingbooleanIndicates if the session is loading.
loadingErrorErrorThe error that occurred while loading the session.
unauthorizedbooleanIndicates if the user is unauthorized.
sessionExpiredbooleanIndicates if the session has expired.
retry() => voidA function to retry loading the session.