---
title: "React, Vue or Angular, frontend only: your frontend"
description: "Install and set up the Block-Auth widget in a React, Vue or Angular app without a backend."
url: "/sdk-integration-frontend-setup/"
language: "en"
guide: "React, Vue, Angular (frontend only)"
step: "Quickstart step 1 of 3, required"
---

# 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:

#### Vite (React · Vue) · development

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

**.env, next to the frontend package.json**

```dotenv
VITE_BLOCKAUTH_API_KEY=your_api_key
```

#### Vite (React · Vue) · production

It’s baked into the build, so it must exist where you build for production. Pick how you build:

**File · .env.production · in your frontend folder**

```dotenv
VITE_BLOCKAUTH_API_KEY=your_api_key
```

**Docker · Dockerfile · right before npm run build**

```dotenv
ARG VITE_BLOCKAUTH_API_KEY
RUN npm run build
```

**Docker · docker-compose.yml · in the service that builds your frontend**

```dotenv
build:
  args:
    VITE_BLOCKAUTH_API_KEY: ${BLOCKAUTH_API_KEY}
```

**CI · Variable of your CI · in the job that runs npm run build**

```dotenv
VITE_BLOCKAUTH_API_KEY=your_api_key
```

#### Next.js (React) · development

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

**.env.local, at the project root**

```dotenv
NEXT_PUBLIC_BLOCKAUTH_API_KEY=your_api_key
```

#### Next.js (React) · production

It’s baked into the build, so it must exist where you build for production. Pick how you build:

**File · .env.production · in your frontend folder**

```dotenv
NEXT_PUBLIC_BLOCKAUTH_API_KEY=your_api_key
```

**Docker · Dockerfile · right before npm run build**

```dotenv
ARG NEXT_PUBLIC_BLOCKAUTH_API_KEY
RUN npm run build
```

**Docker · docker-compose.yml · in the service that builds your frontend**

```dotenv
build:
  args:
    NEXT_PUBLIC_BLOCKAUTH_API_KEY: ${BLOCKAUTH_API_KEY}
```

**CI · Variable of your CI · in the job that runs npm run build**

```dotenv
NEXT_PUBLIC_BLOCKAUTH_API_KEY=your_api_key
```

#### Create React App (React) · development

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

**.env, at the project root**

```dotenv
REACT_APP_BLOCKAUTH_API_KEY=your_api_key
```

#### Create React App (React) · production

It’s baked into the build, so it must exist where you build for production. Pick how you build:

**File · .env.production · in your frontend folder**

```dotenv
REACT_APP_BLOCKAUTH_API_KEY=your_api_key
```

**Docker · Dockerfile · right before npm run build**

```dotenv
ARG REACT_APP_BLOCKAUTH_API_KEY
RUN npm run build
```

**Docker · docker-compose.yml · in the service that builds your frontend**

```dotenv
build:
  args:
    REACT_APP_BLOCKAUTH_API_KEY: ${BLOCKAUTH_API_KEY}
```

**CI · Variable of your CI · in the job that runs npm run build**

```dotenv
REACT_APP_BLOCKAUTH_API_KEY=your_api_key
```

#### Angular (environment.ts) · development

Angular doesn’t use .env: your apiKey goes in this file. If your project doesn’t have it, create the `src/environments` folder (next to `src/app`, not inside it) and this file in it.

**src/environments/environment.ts**

```typescript
export const environment = {
  blockauthApiKey: 'your_api_key',
}
```

#### Angular (environment.ts) · production

Keep `environment.ts` with the development key and put the production one in `environment.prod.ts`, next to it. Then tell `angular.json` to swap them in the production build (`ng build`, the default configuration), so development keeps working on `localhost`.

**src/environments/environment.prod.ts · new file**

```typescript
export const environment = {
  blockauthApiKey: 'your_api_key',
}
```

**angular.json · inside projects › your-app › architect › build › configurations › production**

```dotenv
"fileReplacements": [
  {
    "replace": "src/environments/environment.ts",
    "with": "src/environments/environment.prod.ts"
  }
]
```

#### apiKey written in the widget config (React · Vue · Angular) · development and production

Your apiKey goes straight into the widget config (next step), no environment file.

In the widget config, read the apiKey from that variable instead of writing `your_api_key`:

- Vite (`src/main.jsx · src/main.ts`): `apiKey: import.meta.env.VITE_BLOCKAUTH_API_KEY,`
- Next.js (`app/layout.tsx`): `apiKey: process.env.NEXT_PUBLIC_BLOCKAUTH_API_KEY,`
- Create React App (`src/index.js`): `apiKey: process.env.REACT_APP_BLOCKAUTH_API_KEY,`
- Angular (`src/app/app.config.ts`): `apiKey: environment.blockauthApiKey,`

> **Placeholders in this code:**
>
> - 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:

**React · Terminal · in your package.json folder**

```bash
npm install @block-auth.io/react
```

**Vue · Terminal · in your package.json folder**

```bash
npm install @block-auth.io/vue
```

**Angular · Terminal · in your package.json folder**

```bash
npm install @block-auth.io/angular
```

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.

**Only for Angular:**

**angular.json · At the root of your Angular project**

```json
{
  "projects": {
    "your-app": {
      "architect": {
        "build": {
          "options": {
            "allowedCommonJsDependencies": ["crypto-js", "qrcode", "bs58", "socket.io-client"],
            "externalDependencies": [
              "@base-org/account",
              "@coinbase/wallet-sdk",
              "@metamask/connect-evm",
              "porto",
              "porto/internal",
              "@safe-global/safe-apps-provider",
              "@safe-global/safe-apps-sdk",
              "@walletconnect/ethereum-provider"
            ]
          },
          "configurations": {
            "production": {
              "budgets": [
                { "type": "initial", "maximumWarning": "2MB", "maximumError": "3MB" }
              ]
            }
          }
        }
      }
    }
  }
}
```

> **Placeholders in this code:**
>
> - Replace `your-app` with your project name: the key you already have under `projects` in your `angular.json`.

## 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()`.

**For every setup except React + Next.js:**

**React · src/main.jsx · where your app starts**

```jsx
import { createRoot } from 'react-dom/client'
import { BlockAuthProvider } from '@block-auth.io/react'
import { App } from './App'

const config = {
  apiKey: 'your_api_key',
  authEndpoint: false,
  locale: 'en',
}

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

**Vue · src/main.ts (or main.js) · where your app starts**

```typescript
import { createApp } from 'vue'
import { createBlockAuth } from '@block-auth.io/vue'
import App from './App.vue'

createApp(App)
  .use(
    createBlockAuth({
      apiKey: 'your_api_key',
      authEndpoint: false,
      locale: 'en',
    }),
  )
  .mount('#app')
```

**Angular · src/app/app.config.ts**

```typescript
import { ApplicationConfig } from '@angular/core'
import { provideBlockAuth } from '@block-auth.io/angular'

export const appConfig: ApplicationConfig = {
  providers: [
    provideBlockAuth({
      apiKey: 'your_api_key',
      authEndpoint: false,
      locale: 'en',
    }),
  ],
}
```

> **Placeholders in this code:**
>
> - Replace `your_api_key` with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.

**Only for React + Next.js:**

In Next.js (App Router), the provider goes in a Client Component. Create `app/providers.jsx` and use it in your root `layout`, wrapping `children`. Tested with Next.js 16; with webpack instead of Turbopack (Next.js 15, or `next build --webpack`) the build fails today, so use Turbopack.

**React · app/providers.jsx · new file**

```jsx
'use client'

import { BlockAuthProvider } from '@block-auth.io/react'

const config = {
  apiKey: 'your_api_key',
  authEndpoint: false,
  locale: 'en',
}

export function Providers({ children }) {
  return <BlockAuthProvider config={config}>{children}</BlockAuthProvider>
}
```

> **Placeholders in this code:**
>
> - Replace `your_api_key` with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.

**React · app/layout.jsx · your root layout**

```jsx
import { Providers } from './providers'

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  )
}
```

Any component that uses `FlowBlockAuth` or the hooks also starts with `'use client'`.

**Only for React + Create React App:**

**CRA:** the build warns `Can't resolve '@walletconnect/ethereum-provider'`, an optional dependency the widget doesn't use. You can ignore it; with `CI=true`, CRA turns warnings into errors, so build with `CI=false`.

> **Note:** Never put the `apiSecret` in your app, not even in an environment variable
> like `VITE_…` or `NEXT_PUBLIC_…`: the bundler copies it into the JavaScript
> every visitor downloads. Without a backend you don't need it.

### 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.

**React · Your header · e.g. src/components/Header.jsx**

```jsx
import { FlowBlockAuth } from '@block-auth.io/react'

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

**Vue · Your header · e.g. src/components/AppHeader.vue**

```vue
<template>
  <header>
    <FlowBlockAuth :on-success="onSuccess" :on-error="onError" :on-logout="onLogout" />
  </header>
</template>

<script setup>
import { FlowBlockAuth } from '@block-auth.io/vue'

const onSuccess = (address) => console.log('Signed in as', address)
const onError = () => alert('Sign-in failed, try again.')
const onLogout = () => window.location.assign('/')
</script>
```

**Angular · Your header · e.g. src/app/header.component.ts**

```typescript
import { Component } from '@angular/core'
import { FlowBlockAuthComponent } from '@block-auth.io/angular'

@Component({
  selector: 'app-header',
  imports: [FlowBlockAuthComponent],
  template: `
    <header>
      <ba-flow-block-auth
        (success)="onSuccess($event)"
        (errored)="onError()"
        (loggedOut)="onLogout()"
      />
    </header>
  `,
})
export class HeaderComponent {
  onSuccess(address?: string): void {
    console.log('Signed in as', address)
  }

  onError(): void {
    alert('Sign-in failed, try again.')
  }

  onLogout(): void {
    window.location.assign('/')
  }
}
```

**Only for Angular:**

**Angular with `templateUrl`:** the examples put the HTML inside `template`. If your component has its HTML in its own file (`templateUrl`, the default in new Angular projects, like `app.ts` and `app.html`), move what's inside `template` to that `.html` file and keep the rest (`imports` and the methods) in the `.ts` file.

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](/sdk-integration-frontend-redirect.md). To change how the button looks, see [Customize the widget](/sdk-integration-spa-customize.md).

## 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:

**React · Example · e.g. src/components/Welcome.jsx**

```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>
}
```

**Vue · Example · e.g. src/components/Welcome.vue**

```vue
<script setup>
import { useBlockAuthUser } from '@block-auth.io/vue'

const { user, isLoadingUser } = useBlockAuthUser()
</script>

<template>
  <p v-if="!isLoadingUser">{{ user ? `Signed in as ${user.did}` : 'You are not signed in' }}</p>
</template>
```

**Angular · Example · e.g. src/app/welcome.component.ts**

```typescript
import { Component, inject } from '@angular/core'
import { BlockAuthService } from '@block-auth.io/angular'

@Component({
  selector: 'app-welcome',
  template: `
    @if (auth.user(); as user) {
      <p>Signed in as {{ user.did }}</p>
    } @else if (!auth.isLoadingUser()) {
      <p>You are not signed in</p>
    }
  `,
})
export class WelcomeComponent {
  auth = inject(BlockAuthService)
}
```

To show or hide parts of your UI by role, see [Roles](/sdk-roles.md#frontend). 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](/sdk-integration-frontend-go-live.md#production-csp).

## Checklist

Go over these before trying it. They adapt to your framework and your choices:

The checklist depends on the framework and the choices. Every combination is listed below.

#### 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`.
- If the apiKey is in an environment variable: **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`.
- If the apiKey is written in the widget config: **Your apiKey is in the widget config**: replacing `your_api_key`.
- **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.

#### React · Next.js

- **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 `app/providers.jsx`.
- If the apiKey is in an environment variable: **Your apiKey comes from `NEXT_PUBLIC_BLOCKAUTH_API_KEY`**: in `.env.local`, read with `process.env.NEXT_PUBLIC_BLOCKAUTH_API_KEY`. If a change doesn’t apply, restart `npm run dev`.
- If the apiKey is written in the widget config: **Your apiKey is in the widget config**: replacing `your_api_key`.
- **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.

#### React · Create React App

- **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/index.js`.
- If the apiKey is in an environment variable: **Your apiKey comes from `REACT_APP_BLOCKAUTH_API_KEY`**: in `.env`, read with `process.env.REACT_APP_BLOCKAUTH_API_KEY`. If a change doesn’t apply, restart `npm start`.
- If the apiKey is written in the widget config: **Your apiKey is in the widget config**: replacing `your_api_key`.
- **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.

#### Vue · Vite

- **The package is installed**: `@block-auth.io/vue` shows up in your frontend `package.json`, not in a new one created elsewhere.
- **`createBlockAuth(...)` is registered**: with `.use()` before `.mount()`, in `src/main.ts` (or `main.js`).
- If the apiKey is in an environment variable: **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`.
- If the apiKey is written in the widget config: **Your apiKey is in the widget config**: replacing `your_api_key`.
- **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.

#### Angular

- **The package is installed**: `@block-auth.io/angular` shows up in your frontend `package.json`, not in a new one created elsewhere.
- **`angular.json` has the widget dependencies**: `allowedCommonJsDependencies` and `externalDependencies` in the build options, and an `initial` budget of 2 MB in production.
- **`provideBlockAuth(...)` is in your providers**: in `src/app/app.config.ts`.
- If the apiKey is in an environment variable: **Your apiKey comes from `environment.blockauthApiKey`**: in `src/environments/environment.ts`, imported in `app.config.ts`.
- If the apiKey is written in the widget config: **Your apiKey is in the widget config**: replacing `your_api_key`.
- **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**: `<ba-flow-block-auth>`, 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](/sdk-integration-frontend-try.md).

Next step: [Try it](/sdk-integration-frontend-try.md)
