Skip to main content

Function.useKeybanAuth

function useKeybanAuth(): AuthContext;

Custom hook to access the Keyban authentication context.

This hook provides access to the authentication state and methods managed by the KeybanProvider. It must be called within a component that is a descendant of KeybanProvider.

Returns

AuthContext

The Keyban authentication context object.

Throws

If the hook is used outside of a KeybanProvider.

Example

import React from 'react';
import { useKeybanAuth } from './auth'; // Adjust the import path as needed

function MyAuthenticatedComponent() {
const { isAuthenticated, user, login, logout } = useKeybanAuth();

if (!isAuthenticated) {
return <button onClick={login}>Log In</button>;
}

return (
<div>
<p>Welcome, {user?.name}!</p>
<button onClick={logout}>Log Out</button>
</div>
);
}