React, Vue or Angular

Follow this guide if your frontend is a React, Vue or Angular app. At the end your users sign in with Block-Auth and your backend has a verified session for them.

What you'll build

You need two pieces, and this guide covers both:

  • In your frontend: the Block-Auth widget (@block-auth.io/react, /vue or /angular). It shows the sign-in button and opens the login.
  • In your backend: three routes that redeem the login code with your API secret. Your backend can be in any language: the examples are in Node.js, PHP, Python and .NET.

The browser never decides who the user is: the widget only passes a one-time code to your backend, and your backend gets the user from Block-Auth.

  1. 1Your frontend → Block-AuthLogin in a popup (PKCE)
  2. 2Block-Auth → Your frontendOne-time code
  3. 3Your frontend → Your backendPOST /code
  4. 4Your backend → Block-AuthPOST /api/auth/token
  5. 5Block-Auth → Your backend{ address, roles }
  6. 6Your backend → Your frontendhttpOnly session cookie
  7. 7Your frontend → Your backendGET /me
  8. 8Your backend → Your frontend{ address, roles }

Prepare your app

  1. In the Dashboard, create your application and validate its domain, following the Integration Quickstart. The domain is the host where your frontend runs (for example your-app.com). For development, use a separate app with a domain like dev.your-app.com (one app per environment).
  2. Copy the apiKey and apiSecret from Applications » Show keys. The apiKey is public and goes in your frontend. The apiSecret stays in your backend.
  3. Put them in your backend's environment:

.env (backend)

APP_URL=https://your-app.com
BLOCKAUTH_API_KEY=your_api_key
BLOCKAUTH_API_SECRET=your_api_secret
SESSION_SECRET=a_long_random_string