
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_10npm install @openfort/openfort-kit wagmi viem@^2.22.0 @tanstack/react-query_10_10# Using yarn_10yarn add @openfort/openfort-kit wagmi viem@^2.22.0 @tanstack/react-query_10_10# Using pnpm_10pnpm 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:
- Go to dashboard.openfort.xyz
- Find the API Keys section
- 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_53import React from 'react'_53import { AuthProvider, OpenfortKitProvider, getDefaultConfig, RecoveryMethod } from '@openfort/openfort-kit'_53import { QueryClient, QueryClientProvider } from '@tanstack/react-query'_53import { WagmiProvider, createConfig } from 'wagmi'_53import { polygonAmoy } from 'viem/chains'_53_53// Set up Wagmi_53const 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_53const queryClient = new QueryClient()_53_53export 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_11import React from 'react'_11import { Providers } from './Providers'_11_11export 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_15import { OpenfortKitButton } from '@openfort/openfort-kit'_15_15export 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_22import { useStatus, useUser } from '@openfort/openfort-kit'_22import { useAccount } from 'wagmi'_22_22export 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:
- Add more login options (Facebook, X, whatever)
- Build protected pages that only logged-in users can see
- Add wallet features (send money, sign messages)
- Customize the look and feel more
- Set up account recovery
Helpful Links
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.