sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.31k stars 164 forks source link

Error: Navigating to an external URL is not allowed by default. Use `navigateTo(url, { external: true })`. #775

Closed kaboume closed 4 months ago

kaboume commented 4 months ago

Environment


Reproduction

nuxt.config.ts :


auth: {
    baseURL: "http://localhost:8081/v1/",
    provider: {
      type: "local",
      endpoints: {
        signIn: { path: "/auth/login", method: "post" },
        signOut: { path: "auth/logout", method: "post" },
        signUp: { path: "auth/register", method: "post" },
        getSession: { path: "auth/user", method: "get" },
      },
      token: { signInResponseTokenPointer: "/tokens/access/token" },
    },
  },

Describe the bug

Hi,

When the signin method is executed, this message is thrown :

MyLogin.vue:59 Error: Navigating to an external URL is not allowed by default. Use navigateTo(url, { external: true }). at navigateTo (router.js?v=07f3b5e0:74:13) at signIn (useAuth.mjs?v=07f3b5e0:33:12) at async Proxy.login (MyLogin.vue:50:5)

await signIn({
      email: email.value,
      password: password.value,
      recaptchatoken,
    });
    loading.value = false;
    ....
}

Additional context

No response

Logs

No response

zoey-kaiser commented 4 months ago

For anyone stumbling on this issue: If you need to redirect to an external URL you can pass the flag external into the method to ensure this error does not occur and the redirect is handled properly:

// Trigger a sign-in with a redirect afterwards to an external page (if set, this will cause a hard refresh of the page)
const { signIn } = useAuth() 
await signIn(credentials, { callbackUrl: 'https://sidebase.io', external: true })

Source: https://sidebase.io/nuxt-auth/application-side/session-access-and-management

Suniron commented 3 months ago

I got the same error with a simple signIn without any redirect:

const handleSubmit = async (e: Event) => {
  e.preventDefault()
  const credentials = {
    password: password.value,
    username: login.value,
  }

  isLoading.value = true
  await signIn(credentials)
  isLoading.value = false
}

So, the isLoading.value = false is never reached.

Any idea?