Your frontend

Install and set up the Block-Auth widget in your React, Vue or Angular app, with no backend.

Your environment variables

Your apiKey is public and is all your frontend needs. Here it is with your data:

These files use example values. Fill in your data once in the SDK Quickstart and they come out with yours, ready to copy.Fill in my data

This is your frontend’s .env, at the root of your project.

.env, next to the frontend package.json
VITE_BLOCKAUTH_API_KEY=your_api_key

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 project folder, the one that has the package.json of your React, Vue or Angular app:

Terminal · in your package.json folder
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 project 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. authEndpoint: false is what tells the widget your app has no backend. Your app doesn't change: in React you wrap it as is, and in Vue you add the .use() to the chain you already have, before .mount().

src/main.jsx · where your app startsNew from Block-Auth
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,
  authEndpoint: false,
  locale: 'en',
}

createRoot(document.getElementById('root')).render(
Copy  <BlockAuthProvider config={config}>
    <App />
Copy  </BlockAuthProvider>,
)

Config options

  • apiKey (string, required): your app's API key. It's public: it only says which app is calling.
  • authEndpoint (false): false for an app without a backend. The widget then signs the user in by itself and keeps the session in the browser tab.
  • locale (string): language of the widget, "en" or "es". By default, the browser's language.
  • onSessionEnded (function): called when the session ends outside your page, for example after the user signed out from Block-Auth Identity or the extension. The widget checks it when the tab gets focus and every 5 minutes, and already shows the user as signed out: use it to leave pages for signed-in users.
  • 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.

Add the login button

Place FlowBlockAuth where you want the sign-in button. After the login it turns into the profile menu, with its own sign out, and on reload it restores the session kept in the browser tab. A new tab or window asks to sign in again.

Your header · e.g. src/components/Header.jsxNew from Block-Auth
Copyimport { FlowBlockAuth } from '@block-auth.io/react'

export function Header() {
  return (
    <header>
Copy      <FlowBlockAuth
        onSuccess={(address) => console.log('Signed in as', address)}
        onError={() => alert('Sign-in failed, try again.')}
        onLogout={() => window.location.assign('/')}
      />
    </header>
  )
}

The button opens the login in a popup. 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. More in Login with a redirect. To change how the button looks, see Customize the widget.

Show who is signed in

The widget already shows the profile menu. To use the user in your own components, read it with useBlockAuthUser() in React and Vue, or with the BlockAuthService signals in Angular. user has the address, the did and the roles, or is null if nobody is signed in:

Example · e.g. src/components/Welcome.jsx
import { useBlockAuthUser } from '@block-auth.io/react'

export function Welcome() {
  const { user, isLoadingUser } = useBlockAuthUser()

  if (isLoadingUser) return null
  return <p>{user ? `Signed in as ${user.did}` : 'You are not signed in'}</p>
}

To show or hide parts of your UI by role, see Roles. It only changes what the page shows: don't use it to protect data.

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 trying it. They adapt to your framework and your choices:

React · Vite

  • The package is installed @block-auth.io/react shows up in your frontend package.json, not in a new one created elsewhere.
  • BlockAuthProvider wraps your whole app in src/main.jsx.
  • Your apiKey comes from VITE_BLOCKAUTH_API_KEY in .env, read with import.meta.env.VITE_BLOCKAUTH_API_KEY. If a change doesn’t apply, restart npm run dev.
  • The widget config has authEndpoint: false so the widget signs the user in by itself, without backend routes.
  • The button is where you want it <FlowBlockAuth />, for example in your header.
  • The widget handles the logout after the login the button becomes the profile menu, with its own sign out.
  • The apiSecret isn’t anywhere in your app without a backend you don’t use it, so never put it in the frontend.

Next: Try it.