Skip to content

Commit 77b9da7

Browse files
committed
Remove condition to always send redirect_url for SSO with after-auth (#6498)
1 parent 74deac0 commit 77b9da7

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

.changeset/mighty-ducks-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Remove sending `redirect_url_complete` as `redirect_url` for SSO with after-auth flows

integration/tests/session-tasks-sign-up.test.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
import { createClerkClient } from '@clerk/backend';
12
import { expect, test } from '@playwright/test';
23

34
import { appConfigs } from '../presets';
5+
import { instanceKeys } from '../presets/envs';
46
import type { FakeUser } from '../testUtils';
57
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
8+
import { createUserService } from '../testUtils/usersService';
69

710
testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
811
'session tasks after sign-up flow @nextjs',
912
({ app }) => {
1013
test.describe.configure({ mode: 'serial' });
1114

12-
let fakeUser: FakeUser;
15+
let regularFakeUser: FakeUser;
16+
let fakeUserForOAuth: FakeUser;
1317

1418
test.beforeEach(() => {
1519
const u = createTestUtils({ app });
16-
fakeUser = u.services.users.createFakeUser({
20+
regularFakeUser = u.services.users.createFakeUser({
21+
fictionalEmail: true,
22+
withPhoneNumber: true,
23+
withUsername: true,
24+
});
25+
fakeUserForOAuth = u.services.users.createFakeUser({
1726
fictionalEmail: true,
1827
withPhoneNumber: true,
1928
withUsername: true,
@@ -23,10 +32,18 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
2332
test.afterAll(async () => {
2433
const u = createTestUtils({ app });
2534
await u.services.organizations.deleteAll();
26-
// Delete the user on the OAuth provider instance.
27-
await fakeUser.deleteIfExists();
28-
// Delete the user on the app instance.
29-
await u.services.users.deleteIfExists({ email: fakeUser.email });
35+
await regularFakeUser.deleteIfExists();
36+
37+
// Delete user from OAuth provider instance
38+
const client = createClerkClient({
39+
secretKey: instanceKeys.get('oauth-provider').sk,
40+
publishableKey: instanceKeys.get('oauth-provider').pk,
41+
});
42+
const users = createUserService(client);
43+
await users.deleteIfExists({ email: fakeUserForOAuth.email });
44+
// Delete OAuth user from `with-session-tasks` instance
45+
await u.services.users.deleteIfExists({ email: fakeUserForOAuth.email });
46+
3047
await app.teardown();
3148
});
3249

@@ -41,8 +58,8 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
4158
const u = createTestUtils({ app, page, context });
4259
await u.po.signUp.goTo();
4360
await u.po.signUp.signUpWithEmailAndPassword({
44-
email: fakeUser.email,
45-
password: fakeUser.password,
61+
email: regularFakeUser.email,
62+
password: regularFakeUser.password,
4663
});
4764
await u.po.expect.toBeSignedIn();
4865

@@ -71,7 +88,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
7188
await u.po.signIn.getGoToSignUp().click();
7289

7390
await u.po.signUp.waitForMounted();
74-
await u.po.signUp.setEmailAddress(fakeUser.email);
91+
await u.po.signUp.setEmailAddress(fakeUserForOAuth.email);
7592
await u.po.signUp.continue();
7693
await u.po.signUp.enterTestOtpCode();
7794

packages/clerk-js/src/core/resources/SignIn.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import type {
4343
} from '@clerk/types';
4444

4545
import {
46-
buildURL,
4746
generateSignatureWithCoinbaseWallet,
4847
generateSignatureWithMetamask,
4948
generateSignatureWithOKXWallet,
@@ -251,24 +250,13 @@ export class SignIn extends BaseResource implements SignInResource {
251250
navigateCallback: (url: URL | string) => void,
252251
): Promise<void> => {
253252
const { strategy, redirectUrl, redirectUrlComplete, identifier, oidcPrompt, continueSignIn } = params || {};
254-
255-
const redirectUrlWithAuthToken = SignIn.clerk.buildUrlWithAuth(redirectUrl);
256-
257-
// When after-auth is enabled, redirect to SSO callback route.
258-
// This ensures organization selection tasks are displayed after sign-in,
259-
// rather than redirecting to potentially unprotected pages while the session is pending.
260-
const actionCompleteRedirectUrl = SignIn.clerk.__internal_hasAfterAuthFlows
261-
? buildURL({
262-
base: redirectUrlWithAuthToken,
263-
search: `?redirect_url=${redirectUrlComplete}`,
264-
}).toString()
265-
: redirectUrlComplete;
253+
const actionCompleteRedirectUrl = redirectUrlComplete;
266254

267255
if (!this.id || !continueSignIn) {
268256
await this.create({
269257
strategy,
270258
identifier,
271-
redirectUrl: redirectUrlWithAuthToken,
259+
redirectUrl,
272260
actionCompleteRedirectUrl,
273261
});
274262
}

packages/clerk-js/src/core/resources/SignUp.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,11 @@ export class SignUp extends BaseResource implements SignUpResource {
290290

291291
const redirectUrlWithAuthToken = SignUp.clerk.buildUrlWithAuth(redirectUrl);
292292

293-
// When force after-auth is enabled, redirect to SSO callback route.
294-
// This ensures organization selection tasks are displayed after sign-up,
295-
// rather than redirecting to potentially unprotected pages while the session is pending.
296-
const actionCompleteRedirectUrl = SignUp.clerk.__internal_hasAfterAuthFlows
297-
? redirectUrlWithAuthToken
298-
: redirectUrlComplete;
299-
300293
const authenticateFn = () => {
301294
const authParams = {
302295
strategy,
303296
redirectUrl: redirectUrlWithAuthToken,
304-
actionCompleteRedirectUrl,
297+
actionCompleteRedirectUrl: redirectUrlComplete,
305298
unsafeMetadata,
306299
emailAddress,
307300
legalAccepted,

0 commit comments

Comments
 (0)