question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

404 on api/auth/session when using basePath

See original GitHub issue

Your question

How to set the correct path for /api/auth/session in an app using a custom basePath, it seems like an explicit NEXTAUTH_URL is ignored?

What are you trying to do

I have a global login app at root, running on mysite.com

On successful login, this redirects to another app which sits on a subpath like mysite.com/custom-app/

This app has a custom basePath set in the next.config.js

basePath: '/custom-app',

Login is successful and navigation to the subpath works correctly, but when the session is checked for, it seems to ignore the NEXTAUTH_URL and just checks the session at the default mysite.com/api/auth/session ?

NEXTAUTH_URL=mysite.com/custom-app/api/auth/
Screenshot 2020-09-18 at 15 24 04

If I remove the basePath, everything works correctly when testing between two apps; one running on localhost:8080 the other localhost:3000

Just wondering if I’m missing something, or if this is even possible yet?

Thanks

  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
iaincollinscommented, Sep 28, 2020

@callamwilliams This is really interesting and I don’t actually understand the problem here or why what you did worked.

Please fee free to leave this open for future investigation in case it hints at a bug or just a gap in the docs.

I think the problem could be solved with a pages/_app.js file which sets this option for both client and server side renders, although it looks like this functionality is not documented.

import { Provider } from 'next-auth/client'

export default function App ({ Component, pageProps }) => {
  return (
    <Provider session={pageProps.session} options={{ basePath: `/custom-app/api/auth` }}>
      <Component {...pageProps} />
    </Provider>
  )
}

I’d be interested in knowing if this also worked, instead of using next.config.js to export the env var - although I think exporting the env var that is absolute fine too, and I can see why it resolves the issue with a custom base path (as the NextAuth.js “client” supports being run both browser and server side, and reads in default values for options from env vars if they are set).

1reaction
balazsorban44commented, Apr 17, 2021

For anyone ending up here, I summed up a possible solution at #1713! Please go there and comment on what you think!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next Auth doesn't work with custom basePath - Stack Overflow
My NextAuth are returning 404 when searching for api/auth/session at credential provider custom login, seems like Next Auth are pointing to ...
Read more >
Error 404 when running basic check on base path of sep
I am getting error after trying to access symantec sepm api. Error: Response received from target server404 Not Found. Seems the base path ......
Read more >
Resource not found and HTTP 404 when using z/OS Connect ...
Answer. When reviewing the trace, it is found that the cause of this problem is that the text of the base path is...
Read more >
404 Unable to identify proxy for host: <virtual host name> and url
The client application gets an HTTP status code of 404 with the message Not ... Create a new proxy with a different base...
Read more >
ZOWE endevor plugin for queryacm getting 404
Trying to use the zowe endevor plugin to browse the components of a cobol program to see the copybooks and other dependencies but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found