Reputation: 10329
I'm building a web application that uses cookies to track the user session. These cookies work flawlessly in development on localhost but they aren't working correctly in production. I suspect this is because I have some cookie settings misconfigured but I'm not sure which.
One thing to note is that the webapp runs at app.goldsky.com
and the api runs at api.goldsky.io
(note the different TLDs).
The application I'm building uses a tool called WorkOS for user authentication.
The authentication flow is as follows:
api.goldsky.io
)api.workos/...
) and sends this to the frontendapi.goldsky.io/auth/workos/callback
)/
cookie with the session token (goldsky_session=...
) and redirects the user back to the webapp (app.goldsky.com
)In localhost this all works flawlessly. However, in production I don't see the cookie persist after step 6 completes.
In production, the response to step 5 contains the cookie
however after the redirect back to the webapp, the cookie seems to disappear. Here's the request to app.goldsky.com
(the redirect from step 6) and it doesn't have the cookie header.
and just for completeness, here's a screenshot of the cookies for app.goldsky.com
- it's empty:
By comparison, the final redirect on localhost contains the cookie:
How come my cookie does not persist after redirecting from api.goldsky.io
to app.goldsky.com
? Do I need to set the Domain
attribute for the cookie? If so, what should I set it to? Maybe this is a SameSite
problem?
Upvotes: 0
Views: 840
Reputation: 10329
Turns out I had an nginx misconfiguration issue which was rejecting requests to specific paths. Nginx was only allowing requests to /auth
and a few others. My login logic was under /auth
but the user query was at /user
which nginx was rejecting.
Upvotes: 0