RefirebaseRefirebase

useAuth

new

All-in-one auth hook with ready-to-use sign-in and sign-out actions.

Usage

useAuth combines user state with auth actions in one hook. It eliminates the boilerplate of managing auth state and calling individual auth methods.

useAuth
import { useAuth } from 'refirebase/react';

function AuthButton() {
  const {
    user,
    loading,
    error,
    signInWithGoogle,
    signInWithEmail,
    signUpWithEmail,
    resetPassword,
    signOut,
  } = useAuth();

  if (loading) return <p>Loading...</p>;

  if (!user) {
    return (
      <button onClick={signInWithGoogle}>Sign in with Google</button>
    );
  }

  return (
    <div>
      <p>Hello, {user.displayName}!</p>
      <button onClick={signOut}>Sign out</button>
    </div>
  );
}

Email sign up

signUpWithEmail
const { signUpWithEmail, error } = useAuth();

await signUpWithEmail('alice@example.com', 'password', {
  displayName: 'Alice',
});

if (error) {
  setFieldError(error.message); // user-friendly message
}

Return value

ParamTypeDescription
userUser | nullCurrent Firebase user, or null if not signed in.
loadingbooleanTrue while auth state is being resolved on first render.
errorRefirebaseError | nullLast auth error, if any.
isAuthenticatedbooleanShorthand for !!user.
signInWithGoogle(options?) => PromiseSign in with Google popup.
signInWithGithub(options?) => PromiseSign in with GitHub popup.
signInWithFacebook(options?) => PromiseSign in with Facebook popup.
signInWithEmail(email, password) => PromiseSign in with email and password.
signUpWithEmail(email, password, options?) => PromiseCreate a new account.
resetPassword(email) => PromiseSend a password reset email.
signOut() => PromiseSign out the current user.