refactor: DATA-12840 Avoid passing auth poken as a part of request query params #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What/Why?
We've previously migrated from the approach where we stored auth token in cookies to query params based. Because of the 3rd party cookies deprecation. Now passing the actual token as a part of query params is not safe, so we needed to come up with a more secure approach. Since we use
NextResponse.redirect
method in theload/route
we can not pass it in headers or request body. So that the new flow is the followingload
route we still generate the auth token as we did beforeexchangeToken
, by which we can retrieve the actual auth token. It has a short TTL (currently 2 minutes and may be reduced)NextResponse.redirect
happens as usual though this time we append this temporary exchangeToken to the URL query parameters (it is the only way we can pass something to the next route)src/app/productDescription/[productId]/page.tsx
page where we generate the actual form. Here we get theexchangeToken
from query params and fetch the actualauthToken
from firebase. It can be retrieved only once and then immediately gets removed from firebase.Generator
(and thenForm
) component. We pass the token into the component as an attribute (as we previously did)api/GenerateDescription
route. Previously we passed the token here as a query param too. With this change we pass it in headers instead and get from headers on the API side.Rollout/Rollback
Merge/revert
Testing
Generate description
button and verified that auth token is not passed as a part of request url, but is passed through a request headerScreen.Recording.2025-09-11.at.15.16.42.mov
@bigcommerce/team-data