Skip to content

Authentication Overview

Openfort React supports a variety of authentication flows to onboard users securely.

  • Email/password login
  • Social (OAuth) login (Native methods available)
  • Guest (anonymous) login
  • External wallet (MetaMask, WalletConnect, etc.)

Each method is built for seamless integration with your app, letting you manage user sessions, recovery, and wallet linking with minimal code.

How to authenticate your users

To authenticate your users, there are this hooks available:

Hook NamePurpose & Usage
useEmailAuthEmail/password authentication flows (sign up, login, reset, link)
useOAuthOAuth authentication and linking (Google, Facebook, Twitter, etc)
useGuestAuthGuest user authentication for instant onboarding
useEmailAuthWallet connection and SIWE authentication flows

Third-party authentication

To enable third party authentication add the thirdPartyAuth configuration on the OpenfortProvider.

<OpenfortProvider
    thirdPartyAuth={{
      provider: ThirdPartyOAuthProvider.FIREBASE,
      getAccessToken: async () => {
        return (await auth.currentUser?.getIdToken(/* forceRefresh */ false)) ?? null
      },
    }}
    {/* other props */}
  >
  {/* Your app here */}
</OpenfortProvider>

Then, use the getAccessToken method after logging in, and signOut when signing out. This method exchanges a token from your authentication provider for an Openfort session.

For example, using Firebase:

import { useUser, useSignOut } from '@openfort/react-native';
import { auth } from './lib/firebase';
 
function App() {
  const { getAccessToken } = useUser();
  const { signOut } = useSignOut();
 
  useEffect(() => {
    auth.onAuthStateChanged(user => {
      console.log("onAuthStateChanged");
      if (user) {
        console.log("onAuthStateChanged - User is signed in:", user);
        getAccessToken();
      } else {
        console.log("onAuthStateChanged - No user is signed in");
        signOut();
      }
    });
  }, [])
 
  // ... your app code
};