useAuthController
useAuthController
Section titled “useAuthController”Hook for accessing the authentication state and performing auth-related operations. Works with any backend (Firebase, MongoDB, or custom implementations).
The props provided by this hook are:
userThe currently logged-in user object, ornullif not authenticatedinitialLoadingInitial loading flag, used to avoid showing login screen before auth state is determinedauthLoadingIs the login/logout process ongoingsignOut()Sign out the current userauthErrorError during authentication initializationauthProviderErrorError dispatched by the auth providergetAuthToken()Retrieve the auth token for the current user (returns a Promise)loginSkippedHas the user skipped the login processextraAdditional data stored in the auth controller (useful for roles, permissions, etc.)setExtra(extra)Set additional data in the auth controllersetUser(user)Programmatically set the current user (optional, implementation-dependent)setUserRoles(roles)Set user roles (optional, implementation-dependent)
Example:
import React from "react";import { useAuthController } from "@firecms/core";
export function ExampleCMSView() {
const authController = useAuthController();
if (authController.authLoading) { return <div>Loading...</div>; }
return ( authController.user ? <div>Logged in as {authController.user.displayName}</div> : <div>You are not logged in</div> );}