How to implement Next Auth Shared SSO auth/session/cookies for cross-domains in localhost? #12042
Unanswered
student262512
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
Setup:
OS: Windows
Reverse Proxy: nginx
SSL: mkcert (local SSL)
Domains:
https://auth.example.com - central auth server (Next js, Next Auth)
https://api.example.com - central api server (Next js, Next Auth)
https://example.com - public facing server (Next js, Next Auth)
https://pay.example.com - public facing payment server (Next js, Next Auth)
https://example-times.com - Existing PHP website with user specific blogs/articles & other info
https://example.shop - Existing PHP website for shopping (Must be integrated with https://pay.example.com)
For all the Next Auth based websites, I've setup the below code and config
env:
NEXTAUTH_URL=https://auth.example.com/api/auth
next.config.mjs:
Session Provider in all Nextjs websites:
NextAuthOptions in src/app/api/auth/[...nextauth]/route.ts:
Code in src/middleware.js:
Scenario: When I visit the url "https://example.com" in my local machine, I'd like to auto signin the user as 'Guest', but I keep getting the error "OPTIONS /api/auth/providers 400" in server console log and the error "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://auth.example.com/api/auth/providers. (Reason: CORS request did not succeed). Status code: (null)."
Can anyone help me resolve this issue?
Beta Was this translation helpful? Give feedback.
All reactions