How to Add Authentication to Your React App with Openfort Kit

4 min read

How to Add Authentication to Your React App with Openfort Kit

Authentication can be a pain to build from scratch. But with Openfort Kit, you get a solid auth system that works with both traditional logins and Web3 wallets. Here's how to set it up in React.

Check out the full documentation for more details and support

What You Need

Before we start, make sure you have:

  • Some React and TypeScript knowledge
  • Node.js v20 or higher
  • Your favorite code editor
  • An Openfort account (sign up at dashboard.openfort.xyz)

What We're Building

When we're done, your React app will have:

  • Multiple ways to log in (email, social media, crypto wallets)
  • Non-custodial embedded wallet support
  • Nice-looking UI components that you can customize
  • Secure session management

Step 1: Install the Packages

First, let's get all the packages you need:


_10
# Using npm
_10
npm install @openfort/openfort-kit wagmi viem@^2.22.0 @tanstack/react-query
_10
_10
# Using yarn
_10
yarn add @openfort/openfort-kit wagmi viem@^2.22.0 @tanstack/react-query
_10
_10
# Using pnpm
_10
pnpm install @openfort/openfort-kit wagmi viem@^2.22.0 @tanstack/react-query

Step 2: Get Your API Keys

You'll need some keys from the Openfort Dashboard:

  1. Go to dashboard.openfort.xyz
  2. Find the API Keys section
  3. Grab these:
    • Publishable Key: For your frontend
    • Secret Key: For backend stuff (if you need it)

For non-custodial wallets, you also need Shield keys:

  • Go to the Shield section
  • Click "Create Shield keys"
  • Save that encryption share somewhere safe (you only see it once!)
  • Get your Shield Publishable Key and Shield Secret Key

You'll also need a WalletConnect project ID. Get one by creating a project on the WalletConnect dashboard.

Step 3: Set Up the Providers

Create a file called Providers.tsx to wire everything together:


_53
// Providers.tsx
_53
'use client'
_53
_53
import React from 'react'
_53
import { AuthProvider, OpenfortKitProvider, getDefaultConfig, RecoveryMethod } from '@openfort/openfort-kit'
_53
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
_53
import { WagmiProvider, createConfig } from 'wagmi'
_53
import { polygonAmoy } from 'viem/chains'
_53
_53
// Set up Wagmi
_53
const config = createConfig(
_53
getDefaultConfig({
_53
appName: 'OpenfortKit Demo',
_53
walletConnectProjectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID!,
_53
chains: [polygonAmoy],
_53
ssr: true, // Turn this on if you're using server-side rendering
_53
})
_53
)
_53
_53
// Set up React Query
_53
const queryClient = new QueryClient()
_53
_53
export function Providers({ children }: { children: React.ReactNode }) {
_53
return (
_53
<WagmiProvider config={config}>
_53
<QueryClientProvider client={queryClient}>
_53
<OpenfortKitProvider
_53
publishableKey={process.env.NEXT_PUBLIC_OPENFORT_PUBLIC_KEY!}
_53
walletConfig={{
_53
createEmbeddedSigner: true,
_53
embeddedSignerConfiguration: {
_53
shieldPublishableKey: process.env.NEXT_PUBLIC_SHIELD_PUBLISHABLE_KEY!,
_53
recoveryMethod: RecoveryMethod.PASSWORD,
_53
shieldEncryptionKey: process.env.NEXT_PUBLIC_SHIELD_ENCRYPTION_SHARE!,
_53
}
_53
}}
_53
options={{
_53
authProviders: [
_53
AuthProvider.EMAIL,
_53
AuthProvider.GOOGLE,
_53
AuthProvider.WALLET,
_53
],
_53
initialChainId: polygonAmoy.id,
_53
skipEmailVerification: true, // Only for development
_53
}}
_53
theme="retro" // Pick whatever theme you like
_53
>
_53
{children}
_53
</OpenfortKitProvider>
_53
</QueryClientProvider>
_53
</WagmiProvider>
_53
)
_53
}

Step 4: Wrap Your App

Update your App.tsx to use those providers:


_11
// App.tsx
_11
import React from 'react'
_11
import { Providers } from './Providers'
_11
_11
export default function App() {
_11
return (
_11
<Providers>
_11
{/* Your app goes here */}
_11
</Providers>
_11
)
_11
}

Step 5: Add a Login Button

Create a simple login component with the OpenfortKitButton:


_15
// components/Login.tsx
_15
import { OpenfortKitButton } from '@openfort/openfort-kit'
_15
_15
export function Login() {
_15
return (
_15
<div className="login-container">
_15
<h1>Welcome to Our App</h1>
_15
<OpenfortKitButton
_15
showAvatar={true}
_15
showBalance={true}
_15
label="Connect Wallet"
_15
/>
_15
</div>
_15
)
_15
}

Step 6: Check If Someone's Logged In

Use the built-in hooks to see what's happening with authentication:


_22
// components/AuthStatus.tsx
_22
import { useStatus, useUser } from '@openfort/openfort-kit'
_22
import { useAccount } from 'wagmi'
_22
_22
export function AuthStatus() {
_22
const { status, isConnected } = useStatus()
_22
const { user } = useUser()
_22
const { address } = useAccount()
_22
_22
if (!isConnected) {
_22
return <div>Please connect your wallet</div>
_22
}
_22
_22
return (
_22
<div>
_22
<h2>Welcome!</h2>
_22
<p>Status: {status}</p>
_22
<p>User ID: {user?.id}</p>
_22
<p>Wallet Address: {address}</p>
_22
</div>
_22
)
_22
}

Step 7: Make It Look Good

Openfort Kit uses ConnectKit underneath, so you get lots of customization options. You can change colors, fonts, and more:


_18
<OpenfortKitProvider
_18
// ... other stuff
_18
theme="retro"
_18
customTheme={{
_18
// Change colors, fonts, whatever you want
_18
colors: {
_18
accent: '#FF0000',
_18
background: '#000000',
_18
// ... more colors
_18
},
_18
fonts: {
_18
body: 'Inter, sans-serif',
_18
// ... more fonts
_18
}
_18
}}
_18
>
_18
{children}
_18
</OpenfortKitProvider>

What's Next?

Now that you have basic auth working, you can:

  1. Add more login options (Facebook, X, whatever)
  2. Build protected pages that only logged-in users can see
  3. Add wallet features (send money, sign messages)
  4. Customize the look and feel more
  5. Set up account recovery

That's it! You now have a working authentication system that supports both regular logins and crypto wallets. Your users can pick whatever method they prefer, and you don't have to worry about the security stuff.

Share this article