next-bungie-auth
Version:
Next Bungie Auth is an open source Next.js library that provides a configurable solution for authenticating your users with Bungie.net
60 lines (59 loc) • 2.57 kB
TypeScript
import React from "react";
import type { BungieSessionProviderParams, BungieSession } from "./types";
/**
* Custom hook that returns the Next Bungie Auth Session.
* @returns The Bungie session context.
* @throws If used outside of a BungieSessionProvider.
*/
export declare const useBungieSession: () => BungieSession;
/**
* Custom hook that returns the Next Bungie Auth Session.
*/
export declare const useAuthorizedBungieSession: () => BungieSession & {
status: "authorized";
};
/**
* BungieSessionProvider is a React component that provides Bungie session management functionality.
* It manages the session state, handles session refresh, and provides methods for deauthorization.
*
* NOTE: This this component must be wrapped within a client component if any functional
* (non-serializable) arguments are passed in as props.
*
* @component
* @example
* ```tsx
* <BungieSessionProvider
* initialSession={serverSession}
* onError={(err, type) => console.error(err, type)}
* >
* <App />
* </BungieSessionProvider>
* ```
*/
export declare const BungieSessionProvider: ({ children, initialSession, sessionPath, deauthorizePath, refreshPath, enableAutomaticRefresh, refreshInBackground, fetchOverride: customFetch, timeBeforeRefresh, refreshRateLimit, onError, }: BungieSessionProviderParams) => import("react/jsx-runtime").JSX.Element;
/**
* Within this component, the children will only be rendered even when
* the session is authorized.
*
* This allows you to use the `useAuthorizedBungieSession` hook which guarantees
* the session is authorized in your components.
*
* If a onUnauthorized is provided and the session is unauthorized, the function
* will be called. Commonly used for redirects sign-in pages.
*
* If onUnavailable is provided and the session is unavailable, the function
* will be called. Commonly used for redirects to a maintenance page or to display
* a message to the user.
*/
export declare const BungieSessionSuspender: ({ onUnauthorized, onUnavailable, fallback, children, }: {
children: React.ReactNode;
onUnauthorized?: (session: BungieSession & {
status: "unauthorized";
}) => void;
onUnavailable?: (session: BungieSession & {
status: "unavailable";
}) => void;
fallback: (state: BungieSession & {
status: "unauthorized" | "unavailable" | "stale" | "pending";
}) => React.ReactNode;
}) => string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<React.AwaitedReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;