useAuthCallback
The useAuthCallback hook handles the OAuth callback after a user is redirected back from the authorization server.
Basic Usage
import { useAuthCallback } from 'authsafe-react';
function CallbackPage() {
const { isLoading, error, isSuccess } = useAuthCallback();
if (isLoading) return <div>Processing login...</div>;
if (error) return <div>Login failed: {error.message}</div>;
if (isSuccess) return <div>Login successful! Redirecting...</div>;
return null;
}Return Values
| Property | Type | Description |
|---|---|---|
isLoading | boolean | Whether the callback is being processed |
error | Error | null | Error object if callback processing failed |
isSuccess | boolean | Whether the callback was handled successfully |
Route Setup
Set up a callback route in your application:
// App.tsx
import { BrowserRouter, Route, Routes } from 'react-router-dom';
function App() {
return (
<AuthProvider config={config}>
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/callback" element={<CallbackPage />} />
</Routes>
</BrowserRouter>
</AuthProvider>
);
}Type Definition
interface IUseAuthCallback {
isLoading: boolean;
error: Error | null;
isSuccess: boolean;
}