nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

redirect_uri is always http://localhost:3000

Open bipsen opened this issue 1 year ago • 7 comments

Environment

Working directory: /home/bertilipsen/odin-ui 4:34:56 PM Nuxt project info: 4:34:56 PM



👉 Report an issue: https://github.com/nuxt/nuxt/issues/new 4:34:56 PM

👉 Suggest an improvement: https://github.com/nuxt/nuxt/discussions/new

👉 Read documentation: https://nuxt.com

Reproduction

At the moment, I am unsure how to provide a reproducible repo.

Describe the bug

No matter what I do, I can't seem to get another callback URL other than the default localhost:3000 one. I have tried with various configs, but right now, I simply use:

auth: {
  globalAppMiddleware: true,
},

I set the AUTH_ORIGIN to my website in .env. I have /login page, where I simply redirect immediately, like so:

//pages/login.vue
<template></template>

<script setup lang="ts">
definePageMeta({
  auth: {
    unauthenticatedOnly: true,
    navigateAuthenticatedTo: "/",
  },
  layout: "blank",
});

const { signIn } = useAuth();

signIn("auth0");
</script>

This is my handler:

//server/api/auth/[...].ts

import { NuxtAuthHandler } from "#auth";
import Auth0Provider from "next-auth/providers/auth0";

const runtimeConfig = useRuntimeConfig();

export default NuxtAuthHandler({
  secret: runtimeConfig.auth.secret,
  pages: {
    signIn: "/login",
  },
  providers: [
    // @ts-expect-error
    Auth0Provider.default({
      clientId: runtimeConfig.auth0.clientId,
      clientSecret: runtimeConfig.auth0.clientSecret,
      issuer: runtimeConfig.auth0.issuer,
      audience: runtimeConfig.auth0.audience,
      idToken: true,
      authorization: {
        params: {
          audience: encodeURI(runtimeConfig.auth0.audience),
        },
      },
    }),
  ],
});

Additional context

No response

Logs

No response

bipsen avatar Feb 12 '24 15:02 bipsen

I'm seeing similar issues on any other provider. As a matter of fact, same behaviour even when trying out the https://github.com/sidebase/nuxt-auth-example repo.

matthewairalo avatar Feb 13 '24 10:02 matthewairalo

I am encountering the same problem, I found a fix for it by defining the NEXTAUTH_URL in my .env file, problem with this is that it sets the cookie to Secure, and that will result in the cookie not getting set. image

It is possible to disable Secure Cookies using the NuxtAuthHandler like this:

export default NuxtAuthHandler({
    // ...
    useSecureCookies: false,
    // ...
})

FrankoFM avatar Feb 14 '24 15:02 FrankoFM

Also running into this issue unfortunately. Tried setting the callbackUrl in the signIn method and the baseURL in the auth prop of the nuxt config as well as the devServer prop but it just stubbornly defaults to localhost:3000. NEXTAUTH_URL "fixes" that of course but I don't feel like that's an elegant or modular approach unfortunately

warflash avatar Feb 20 '24 14:02 warflash

Yeah, this is 100% not elegant or the correct way of doing this, sadly this project only has @zoey-kaiser working on it in her free time, so its slowly falling apart. No hate to you zoey but this project has seen better times, you are doing a great job!

FrankoFM avatar Feb 21 '24 13:02 FrankoFM

Yeah, this is 100% not elegant or the correct way of doing this, sadly this project only has @zoey-kaiser working on it in her free time, so its slowly falling apart.

I completely agree! We have recently introduced a new developer to the project to help sort out some of these issues! As he is currently still getting into the project it may take another week for regular updates and more activity to come 🤗

No hate to you zoey but this project has seen better times, you are doing a great job!

Thank you for the compliment! I hope it will become better soon. Next week, I will dedicate a good amount of time, to sorting through every issue, doing some triage and prioritizing them based on importance.

zoey-kaiser avatar Feb 21 '24 14:02 zoey-kaiser

@zoey-kaiser thanks for the work you do here, it's great to have multiple options for auth!

tesla3327 avatar Feb 29 '24 15:02 tesla3327

Any news about that topic? i have the same issue but can not circumvent it by using NEXTAUTH_URL because in my deployment process all the env variables get mandatorily prefixed with (e.g) 'BLA_'. so it will result in BLA_NEXTAUTH_URL

tbslchnr avatar Mar 25 '24 14:03 tbslchnr