Login with a redirect

The widget button opens the login in a popup. If the browser blocks it, the widget opens the login in the same tab instead, with nothing to add to your code.

How it works

  1. The browser blocks the popup: the widget takes the user to the Block-Auth login in the same tab.
  2. After signing in, Block-Auth sends the user back to the root of your app (https://your-app.com/), always to /.
  3. The widget reloads the page where the user started and finishes the login there: it shows their profile menu and calls onSuccess. If the user rejects the login, it calls onError.

Your root (/) must load your app with the widget config, which is what React, Vue and Angular apps do by default.

From your own button

To always use the same tab, without trying the popup, call loginWithRedirect() from your own button. If the page where the user starts shows FlowBlockAuth, it finishes the login by itself; otherwise, call handleRedirectCallback() once when that page loads. It does nothing if the page doesn't come from a login, so you can call it on every load.

Your root component · e.g. src/App.jsxNew from Block-Auth
Copyimport { useEffect } from 'react'
import { useClient } from '@block-auth.io/react'

export function App() {
Copy  const client = useClient()

Copy  useEffect(() => {
    client
      .handleRedirectCallback()
      .catch(() => alert('Sign-in failed, try again.'))
  }, [client])

  return (
    <main>
Copy      <button
        onClick={() =>
          client
            .loginWithRedirect()
            .catch(() => alert('Sign-in failed, try again.'))
        }
      >
        Sign in
      </button>
    </main>
  )
}

If the user rejects the login on Block-Auth, handleRedirectCallback() fails and your catch runs. After signing in, FlowBlockAuth shows the profile menu with its sign out; if you don't use the widget, sign out with client.logout().