Hooks (client-side)
useAuth()
The useAuth()
hook provides access to the current user’s authentication state.
Returns
An object with the following properties:
isLoading
boolean
A boolean indicating whether the authentication state is still being loaded.
user
User | null
The User object of the currently authenticated user, or null
if the user is not authenticated.
isAuthenticated
boolean
A boolean indicating whether the user is authenticated.
login
function
A function that can be called to initiate the login process.
logout
function
A function that can be called to initiate the logout process.
Examples
import { useAuth } from "@kobbleio/next/client";
export default function MyComponent() {
const { isLoading, user, isAuthenticated } = useAuth();
if (isLoading) {
return <p>Loading...</p>;
}
if (isAuthenticated) {
return (
<div>
<p>Welcome, {user.name}!</p>
</div>
);
}
return (
<div>
<p>You are not logged in.</p>
</div>
);
}