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 following the Integration Quickstart. As the domain, enter the host where your frontend runs (for example your-app.com).
  2. Pick the keys based on where your app is going to run. Each environment has its own in Applications » Integration details, and they don't mix:
Where your app runsWhich keys to useWhere you put them
Your computer (localhost)The Development ones. They work right away.The .env on your computer
Your live serverThe Production ones. They work once you validate your domain.Your server's environment variables
  1. Fill in your data once in the SDK Quickstart: from then on, each guide gives you the files and code already adapted to your app.