npm install authsafe-reactimport { AuthProvider } from 'authsafe-react';
function App() {
return (
<AuthProvider
config={{
clientId: 'your-client-id',
redirectUri: 'http://localhost:3000/callback',
scope: ['openid', 'profile', 'email'],
env: 'production'
}}
>
<YourApp />
</AuthProvider>
);
}import { useLogin, useAuth, useLogout } from 'authsafe-react';
function MyApp() {
const { login } = useLogin();
const { user, isAuthenticated } = useAuth();
const { logout } = useLogout();
if (!isAuthenticated) {
return <button onClick={() => login()}>Login</button>;
}
return (
<div>
<h1>Welcome, {user?.name}!</h1>
<button onClick={logout}>Logout</button>
</div>
);
}interface AuthConfig {
clientId: string; // Required: Your application's client ID
redirectUri: string; // Required: OAuth callback URL
scope?: Array<AuthScope>; // Optional: Requested scopes
env?: 'development' | 'production'; // Optional: Environment
authority?: string; // Optional: Custom authority URL
popupRedirectUri?: string; // Optional: Popup redirect URL
automaticSilentRenew?: boolean; // Optional: Auto-renew tokens
}