mirror of
https://github.com/games-on-whales/wolfmanager.git
synced 2026-10-15 21:12:13 +00:00
[GH-ISSUE #40] Changing NEXTAUTH_URL behind reverse proxy doesn't work #19
Labels
No labels
a11y
bug
enhancement
enhancement
good first issue
pull-request
question
refactor
security
shadcn
tech-debt
ui
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
games-on-whales/wolfmanager#19
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shawly on GitHub (Jun 24, 2025).
Original GitHub issue: https://github.com/games-on-whales/wolfmanager/issues/40
I just wanted to try out wolfmanager and set up a compose stack with wolf.
Since I use traefik as reverse proxy, I set the NEXTAUTH_URL to the domain where wolfmanager will be reachable, e.g. NEXTAUTH_URL=https://wolf.example.com
This causes wolfmanager to redirect weirdly which causes my session to be unauthorized even though the login mask accepted my credentials.
When I set NEXTAUTH_URL back to http://localhost:3000 I could login just fine and could view the dashboard etc.
But now when I click on the logout button I get redirected to http://localhost:3000/login.
According to the NextAuth docs, in a production environment NEXTAUTH_URL should be set to the actual domain, like I did.
I also tried setting AUTH_TRUST_HOST=true and NEXTAUTH_TRUST_HOST=true as the docs suggest, but that didn't help either.
@salty2011 commented on GitHub (Jun 26, 2025):
Hey @shawly
Yup I have taken a look and i can see where this has been hardcoded instead of using the nextauth variable.
Thanks will get this sorted asap... also was doing some research and apparently there are some additional things to add as part of the headers so this will work correctly a reverse proxy is in the mix.
As for the other change you had submitted for permission optimization happy for you to merge that branch into 202506.004 where I am staging all changes for the next release before months end.
Was hoping to get SSE working for live updates along with client info. But have ran into some issues due to internal auth
@salty2011 commented on GitHub (Jul 7, 2025):
hey @shawly
Ive just pushed a new branch I think should resolve the described issues. Are you able give this image a go, you should only need to set the NEXTAUTH_URL to public address.
ghcr.io/games-on-whales/wolfmanager/wolfmanager:fix-issue-40-nextauth-url
If you can let know how that goes and any config instructions for the reverse proxy ill add that info into the documentation as well.
@shawly commented on GitHub (Jul 7, 2025):
Hi @salty2011,
just tested the image with NEXTAUTH_URL set to my public address and the same issue persists.
The log shows this:
I made sure to clean out my session storage and cookies before trying.
I also tried setting the AUTH_TRUST_HOST env var to no avail. Setting NEXT_AUTH_URL back to http://localhost:3000 made it work again.
@salty2011 commented on GitHub (Jul 7, 2025):
hey @shawly
Just confirming the testing was done with this image https://github.com/games-on-whales/wolfmanager/releases/tag/preview-202506.004
Oh another thing you may want to try doing a clean state as part of SSE implementation I changed how secrets are auto-generated. would just need wolfmanager.db and .env.local are removed to allow them to regenerate.
@shawly commented on GitHub (Jul 7, 2025):
I now also tested ghcr.io/games-on-whales/wolfmanager/wolfmanager:preview-202506.004 and I also cleaned the whole config folder to have a clean slate and the issue still persists.
On the first start I log in with admin:admin then I am greeted with this screen:
When I click the Log in button there, I am redirected to the /first-time-setup route where I can set a new password for the admin account which does work. Afterwards when I login with my new password I constantly land on the authentication required page like in the screenshot, instead of the dashboard.
@salty2011 commented on GitHub (Jul 7, 2025):
🔍 Enhanced JWT Debugging Implemented
I've added comprehensive JWT debugging capabilities to help identify the root cause of the NextAuth reverse proxy JWT validation issue.
🚀 Changes Made
Branch:
fix/issue-40-nextauth-urlCommit:
ad3351bNew JWT Debug Utility (
src/lib/debug/jwt-debug.ts)x-forwarded-*)Enhanced Auth Configuration (
src/lib/auth.ts)Enhanced Middleware (
src/middleware.ts)🔧 Testing Instructions
fix/issue-40-nextauth-urlbranchFor URL Context Mismatch (Most Likely Cause):
For Cookie Configuration Issues:
🎯 What to Look For
The logs will show:
📋 Next Steps
x-forwarded-proto,x-forwarded-host)🔧 Potential Quick Fixes
Based on the analysis, try these if the debugging confirms by adding these environment variables to the wolfmanager compose:
For URL Context Mismatch:
For Cookie Security Issues:
Please test this enhanced debugging version and share the JWT_DEBUG log entries when you encounter the "JWT invalid" error. This will help us pinpoint the exact cause and provide a targeted fix.
@salty2011 commented on GitHub (Jul 7, 2025):
@shawly > lol I was testing the new github integration with the AI issue management. However the images is currently building.
When its completed building youll need to force update the image. Then proceed with the above testing steps.
Cause i dont have a reverse proxy setup in my environment at the moment will need as much detail as you can give
I think the issue is related to mismatch of url in the cookies. The cookie should have the public url but i think it may be ending up with the localhost address.
Another test to try is confirm how this is working without the reverse proxy / local. From what i am reading there maybe some additional things I need to do to support reverse proxy.
@shawly commented on GitHub (Jul 7, 2025):
wolfman.log
Here's the log, looking at the cookie it seems the domain is the public one not the localhost address.
@salty2011 commented on GitHub (Jul 9, 2025):
🔍 Root Cause Identified: Cookie Name Mismatch
I've analyzed the JWT debugging logs you provided, and I found the exact root cause of the issue!
❌ The Problem: Cookie Security Mismatch
The logs clearly show a cookie name mismatch:
What NextAuth expects (production with secure cookies):
What the browser is actually sending:
🔧 The Root Cause
NextAuth is running in production mode with SSL-aware settings, so it's expecting secure cookies with the
__Secure-prefix. However, because your SSL termination happens at the reverse proxy level (Traefik), NextAuth should be configured to use non-secure cookies internally.✅ The Fix
Add this environment variable to your
wolfmanagerservice in docker-compose:📋 What This Does
Setting
INSECURE_COOKIES_IN_PRODUCTION=truetells NextAuth:next-auth.session-tokeninstead of__Secure-next-auth.session-tokenSecureflag on cookies (since SSL termination is handled by reverse proxy)🎯 Why This Happens
This is a common reverse proxy configuration issue:
🚀 Next Steps
This should resolve the JWT validation issue completely. The debugging logs show everything else is configured correctly - URL contexts match perfectly, reverse proxy headers are forwarded properly, it's just the cookie security configuration that needs adjustment.
Let me know if this fixes the issue!
@salty2011 commented on GitHub (Jul 9, 2025):
Hey @shawly
can you please retest with the aforementioned "INSECURE_COOKIES_IN_PRODUCTION=true" environment variable and confirm if this resolves the issue.
Would be keen to see the log either way. Assuming this works.
@salty2011 commented on GitHub (Jul 11, 2025):
✅ Issue Resolved - Automatic Reverse Proxy Detection Implemented
🎯 Root Cause Identified
The issue was caused by a NextAuth cookie security configuration mismatch when running behind reverse proxies:
__Secure-next-auth.session-token)🚀 Solution Implemented
Automatic Reverse Proxy Detection
src/lib/auth/reverse-proxy-detection.tsx-forwarded-for,x-forwarded-host,x-forwarded-protox-real-ip,cf-connecting-ip(Cloudflare)x-amzn-trace-id(AWS ALB)Dynamic Cookie Configuration
Enhanced Debugging & Error Handling
✅ Testing Results
🔧 Configuration Options
Manual Override (Optional)
📋 Key Benefits
🎯 Resolution Summary
@shawly This should resolve your Traefik reverse proxy authentication issues. The system now automatically detects when it's running behind a reverse proxy and configures cookies appropriately. Please test and let us know if you encounter any issues!
Commit:
6966225@shawly commented on GitHub (Jul 12, 2025):
Awesome thanks! Works with AUTH_TRUST_HOST=true and my domain for the NEXTAUTH_URL perfectly fine now!
@salty2011 commented on GitHub (Jul 12, 2025):
@shawly so you needed the AUTH_TRUST_HOST before it worked?
Curious in my testing that wasn't needed but the hostname i was using was http://localhost/
Out of interest does having that set work even without reverse proxy and just using IP?
Asking cause I could just build that variable into the container image so it's not required to be set
@shawly commented on GitHub (Jul 13, 2025):
I just tested again and AUTH_TRUST_HOST isn't necessary at all. Dunno what went wrong yesterday without this var.