---
title: "React, Vue or Angular, frontend only: login with a redirect"
description: "What the widget does when the browser blocks the login popup, and how to open the login in the same tab from your own button."
url: "/sdk-integration-frontend-redirect/"
language: "en"
guide: "React, Vue, Angular (frontend only)"
step: "More options, optional"
---

# 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](/sdk-integration-frontend-setup.md#configure-widget), 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.

**React · Your root component · e.g. src/App.jsx**

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

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

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

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

**Vue · Your root component · e.g. src/App.vue**

```vue
<template>
  <main>
    <button @click="login">Sign in</button>
  </main>
</template>

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

const client = useClient()
const login = () =>
  client.loginWithRedirect().catch(() => alert('Sign-in failed, try again.'))

onMounted(() => {
  client.handleRedirectCallback().catch(() => alert('Sign-in failed, try again.'))
})
</script>
```

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

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

@Component({
  selector: 'app-root',
  template: `
    <main>
      <button (click)="login()">Sign in</button>
    </main>
  `,
})
export class AppComponent implements OnInit {
  private readonly client = injectBlockAuthClient()

  ngOnInit(): void {
    this.client
      .handleRedirectCallback()
      .catch(() => alert('Sign-in failed, try again.'))
  }

  login(): void {
    this.client
      .loginWithRedirect()
      .catch(() => alert('Sign-in failed, try again.'))
  }
}
```

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

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