Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpressAuth ignores AUTH_URL and basePath #11887

Open
noam-honig opened this issue Sep 21, 2024 · 3 comments
Open

ExpressAuth ignores AUTH_URL and basePath #11887

noam-honig opened this issue Sep 21, 2024 · 3 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@noam-honig
Copy link
Contributor

Environment

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz
    Memory: 7.70 GB / 31.68 GB
  Binaries:
    Node: 20.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.6 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @auth/express: ^0.6.1 => 0.6.1
    react: ^18.3.1 => 18.3.1

Reproduction URL

https://github.com/noam-honig/demo-auth-problem-with-proxy

Describe the issue

I'm developing an app, using vite frontend with express and ExpressAuth as the backend.

I'm using vite's proxy option (in the vite.config.ts file to forward api and auth requests to the express backend on port 3002.

When I navigate to:
localhost:5173/auth/signout
And click ok - it navigates to:
localhost:3002 <-- the port for the backend
Instead of to localhost:5173 that I wanted.

I tried setting the AUTH_URL in the .env file - but:
a. It was ignored
b. it gave the following warning in the code: [auth][warn][env-url-basepath-redundant] Read more: https://warnings.authjs.dev#env-url-basepath-redundant

How to reproduce

  1. Clone the repo
  2. npm i
  3. Open two terminals
    3.1. run npm run dev in the first
    3.2 run 'npm run dev-node' in the second
  4. navigate to the url http://localhost:5173/auth/signout
  5. Click sign out

it'll take you to localhost:3002 and not 5173

Try setting the AUTH_URL in the .env
it'll give the following warning in the console:
[auth][warn][env-url-basepath-redundant] Read more: https://warnings.authjs.dev#env-url-basepath-redundant
even when basePath wasn't set

Expected behavior

  1. Best result - will go back to the localhost:5173 without any configuration.
  2. I can live with setting the AUTH_URL in the .env file - but that it'll be used
@noam-honig noam-honig added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Sep 21, 2024
@hillac
Copy link
Contributor

hillac commented Sep 22, 2024

I think what you want to set is the callbackUrl option, not the AUTH_URL env var. You'll have to allow it to redirect the the front end in the redirect callback in your config, or set callbackUrl to a route in the backend whose handler redirects you to the front end.

@noam-honig
Copy link
Contributor Author

@hillac I'll look into that - but please don't skip the second part, where if I set AUTH_URL in the .env - it gives the error and is ignored.

@hillac
Copy link
Contributor

hillac commented Sep 23, 2024

Yeah, the maintainers added this line here:

config.basePath = getBasePath(req)

It auto sets the basePath from the route so you shouldn't need to set it. The setEnvDefaults function will ignore the AUTH_URL if baseUrl is already set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants