Skip to content

Commit

Permalink
fix(backend,nextjs): Replace DevBrowser constant usage for query para…
Browse files Browse the repository at this point in the history
…ms (#3355)

* fix(backend,nextjs): Replace DevBrowser constant usage for query params

Instead of using Cookies.DevBrowser we should use
QueryParameters.DevBrowser when adding dev browser
token to the url for consistency even though both
constants have the same value

* fix(backend): Replace Handshake constant usage for query params

Instead of using Cookies.Handshake we should use QueryParameters.Handshake
  • Loading branch information
dimkl committed May 10, 2024
1 parent 7b213d5 commit 558430d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .changeset/lemon-plums-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/backend/src/createRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const buildUrl = (
}
// For cross-origin redirects, we need to pass the dev browser token for URL session syncing
if (_devBrowserToken && baseUrl.hostname !== res.hostname) {
res.searchParams.set(constants.Cookies.DevBrowser, _devBrowserToken);
res.searchParams.set(constants.QueryParameters.DevBrowser, _devBrowserToken);
}
return res.toString();
};
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/tokens/authenticateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class AuthenticateContext {

private initHandshakeValues() {
this.devBrowserToken =
this.clerkRequest.clerkUrl.searchParams.get(constants.Cookies.DevBrowser) ||
this.clerkRequest.clerkUrl.searchParams.get(constants.QueryParameters.DevBrowser) ||
this.clerkRequest.cookies.get(constants.Cookies.DevBrowser);
this.handshakeToken =
this.clerkRequest.clerkUrl.searchParams.get(constants.Cookies.Handshake) ||
this.clerkRequest.clerkUrl.searchParams.get(constants.QueryParameters.Handshake) ||
this.clerkRequest.cookies.get(constants.Cookies.Handshake);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/tokens/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ ${error.getFullMessage()}`,
/**
* Otherwise, check for "known unknown" auth states that we can resolve with a handshake.
*/
if (instanceType === 'development' && authenticateContext.clerkUrl.searchParams.has(constants.Cookies.DevBrowser)) {
if (
instanceType === 'development' &&
authenticateContext.clerkUrl.searchParams.has(constants.QueryParameters.DevBrowser)
) {
return handleMaybeHandshakeStatus(authenticateContext, AuthErrorReason.DevBrowserSync, '');
}

Expand Down Expand Up @@ -284,7 +287,7 @@ ${error.getFullMessage()}`,

if (authenticateContext.devBrowserToken) {
redirectBackToSatelliteUrl.searchParams.append(
constants.Cookies.DevBrowser,
constants.QueryParameters.DevBrowser,
authenticateContext.devBrowserToken,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const auth = (): Auth => {
const redirectToSignIn: RedirectFun<never> = (opts = {}) => {
const clerkRequest = createClerkRequest(request);
const devBrowserToken =
clerkRequest.clerkUrl.searchParams.get(constants.Cookies.DevBrowser) ||
clerkRequest.clerkUrl.searchParams.get(constants.QueryParameters.DevBrowser) ||
clerkRequest.cookies.get(constants.Cookies.DevBrowser);

return createRedirect({
Expand Down

0 comments on commit 558430d

Please sign in to comment.