Your frontend
Install and set up the Block-Auth widget in your React, Vue or Angular app.
Your environment variables
Before you touch any code, create the .env files for your frontend and your backend. Your apiKey is public and goes in the frontend; your apiSecret goes only in the backend. Here they are with your data:
This is your frontend’s .env. The backend has its own file.
VITE_BLOCKAUTH_API_KEY=your_api_keyReplace your_api_key with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.
In a .env next to your backend package.json. Load it with node --env-file=.env (Node 20.6+) or the dotenv package (import 'dotenv/config' at the top of your entry file).
APP_URL=http://localhost:5173
BLOCKAUTH_API_KEY=your_api_key
BLOCKAUTH_API_SECRET=<paste the API Secret from the Dashboard>
SESSION_SECRET=<generate one: openssl rand -hex 32>
Replace the API Secret placeholder with your API Secret, copied straight from the Dashboard. Never paste it on this site.
Replace the SESSION_SECRET placeholder with a random value generated on your computer: openssl rand -hex 32.
Replace your_api_key with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.
Install the widget
Run it in your frontend folder, the one that already has the package.json of your React, Vue or Angular app. If your frontend is in a subfolder, like frontend/ or client/, go into it first. If frontend and backend share one package.json, it's the project root:
npm install @block-auth.io/react
Check that the package shows up in that package.json. If npm created a new package.json, you were in another folder: delete it along with its node_modules and run the install again in your frontend folder.
Angular: the widget brings wallet libraries with CommonJS modules and optional dependencies the Angular builder can't resolve. Add them to the build options in angular.json, or the build warns and fails. Also raise the initial budget of the production build: the wallets add about 1 MB and the default limit of new Angular projects (1 MB) stops ng build. If your angular.json already has budgets, change only the initial one. Select the Angular tab to see the configuration.
Configure the widget
Add it once, in the file where your app starts: src/main.jsx in React with Vite (src/index.js with CRA), src/main.ts (or src/main.js) in Vue and app.config.ts in Angular. Your app doesn't change: in React you wrap it as is, with everything it already has inside, and in Vue you add the .use() to the chain you already have (for example, next to .use(router)), before .mount().
import { createRoot } from 'react-dom/client'
Copyimport { BlockAuthProvider } from '@block-auth.io/react'
import { App } from './App'
Copyconst config = {
apiKey: import.meta.env.VITE_BLOCKAUTH_API_KEY,
locale: 'en',
}
createRoot(document.getElementById('root')).render(
Copy <BlockAuthProvider config={config}>
<App />
Copy </BlockAuthProvider>,
)
Never put the apiSecret in your frontend, not even in an environment
variable like VITE_… or NEXT_PUBLIC_…: the bundler copies it into the
JavaScript every visitor downloads. The widget doesn't need it: if you pass
it, the SDK sends it from the browser.
Config options
apiKey(string, required): your app's API key. It's public: it only says which app is calling.authEndpoint(string | false): base path of your backend routes. By default/auth/blockauth: set it only if your routes live under another path, and set the same path asbasePathin your backend package. To turn off a package route you don’t use, passroutes: { link: false }(in .NET,DisabledRoutes). Serve it from the same origin as your frontend, so the session cookie travels with every request. If a route is missing or doesn't answer, the browser console says what to fix. Set it tofalseonly if your app has no backend: the widget then signs the user in by itself, and your page knows their address but your server has no session it can trust.locale(string): language of the widget,"en"or"es". By default, the browser's language.sessionCheckSeconds(number): how often the widget asks/mewhether the session is still open, besides every time the tab gets focus. By default60;0turns it off.onSessionEnded(function): called when your backend has closed the session, for example after the user signed out from Block-Auth Identity or the extension. The widget already shows the user as signed out: use it to leave private pages.wsUrl(string): the Block-Auth server the widget talks to. By default production (wss://wss.block-auth.io): change it only if Block-Auth gives you another environment to test against.
The login itself happens on the Block-Auth login page (auth.block-auth.io), so you don't configure Google, Microsoft, wallets or WalletConnect in your app.
Your app today
Applies from here on. You pick it once in the SDK Quickstart.
Add the login button
Put FlowBlockAuth on your login page, below your form, as another way in. Don't replace your page: add only the FlowBlockAuth import and the component right after your form (in Vue and Angular, also the onSuccess and onError functions). In the example, the <form> is your current form, which stays the same. After the login, reload the page: your app asks your backend again who the user is, and your backend resolves it with your session or Block-Auth's.
Copyimport { FlowBlockAuth } from '@block-auth.io/react'
export function LoginPage() {
return (
<main>
<form method="post" action="/login">
⋯ Generic example (3 lines)Hide generic example <input name="email" type="email" />
<input name="password" type="password" />
<button type="submit">Sign in</button>
</form>
Copy <FlowBlockAuth
onSuccess={() => window.location.assign('/')}
onError={() => alert('Sign-in failed, try again.')}
/>
</main>
)
}
When signing out, also close the Block-Auth session: in the function where you already sign out, add a call to POST /auth/blockauth/logout with a JSON {} body. It works the same in React, Vue and Angular. In the example, /api/logout is your current logout, which stays the same:
Logout
async function logout() {
await fetch('/api/logout', { method: 'POST' })
Copy await fetch('/auth/blockauth/logout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{}',
})
window.location.assign('/login')
}
To let your current users reach their same account, link them.
If the browser blocks the popup, the widget opens the login in the same tab: Block-Auth sends the user back to the root of your app (/), which must load your frontend with the widget config, and the widget finishes the login on the page where it started.
Does your server send a Content-Security-Policy? You won’t notice in development, but in production it blocks the widget: unstyled button, broken logo and failed login. When you deploy, allow it as explained in Go live.
Checklist
Go over these before moving on to the backend. They adapt to your framework and your choices:
React · Vite
- The package is installed
@block-auth.io/reactshows up in your frontendpackage.json, not in a new one created elsewhere. BlockAuthProviderwraps your whole app insrc/main.jsx.- Your apiKey comes from
VITE_BLOCKAUTH_API_KEYin.env, read withimport.meta.env.VITE_BLOCKAUTH_API_KEY. If a change doesn’t apply, restartnpm run dev. - The button sits next to your login form
<FlowBlockAuth />on your login page, reloading the page inonSuccess. - Your logout also closes the Block-Auth session with a
POST /auth/blockauth/logoutand a JSON{}body, after your own logout. - The
apiSecretisn’t in the frontend not even in aVITE_…variable: it only goes in your backend.
Login doesn’t work yet: your backend is missing. You test it end to end in the last step, Connect and try it.

