AuthProvider
React context provider that wraps your application and provides authentication state to all components.
Overview
The AuthProvider component creates a React context that manages authentication state, handles automatic token refresh, and provides auth methods to all child components via hooks. All client-side hooks (useAuth, useSession, useMfa) require AuthProvider to be present in the component tree.
Basic Usage
import { AuthProvider } from 'authsafe-nextjs';
export default function RootLayout({ children }) {
return (
<AuthProvider
config={{
clientId: process.env.NEXT_PUBLIC_AUTHSAFE_CLIENT_ID,
domain: process.env.NEXT_PUBLIC_AUTHSAFE_DOMAIN,
}}
>
{children}
</AuthProvider>
);
}