RefirebaseRefirebase

getAccessToken

Get the current user's Firebase ID token.

Usage

Use getAccessToken to retrieve the JWT ID token. Useful for authenticating API requests to your backend.

TokenDisplay.tsx
import { useRefirebase } from 'refirebase/react';

export function TokenDisplay() {
  const { auth } = useRefirebase();

  const handleGetToken = async () => {
    const token = await auth.getAccessToken(true);
    console.log('Access token:', token);
  };

  return <button onClick={handleGetToken}>Log Token</button>;
}

Parameters

ParamTypeDescription
forceRefreshbooleanWhether to force a token refresh. Defaults to false.

Return value

Returns

Promise<string | null>

The ID token string, or null if no user is signed in.