Skip to content

Commit 69498df

Browse files
feat(clerk-js): Introduce navigate for setActive (#6486)
Co-authored-by: Nikos Douvlis <[email protected]>
1 parent 59f1559 commit 69498df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+724
-625
lines changed

.changeset/rich-donuts-agree.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
---
5+
6+
Add `navigate` parameter to `clerk.setActive()` for custom navigation before the session and/or organization is set.
7+
8+
It's useful for handling pending session tasks for after-auth flows:
9+
10+
```typescript
11+
await clerk.setActive({
12+
session,
13+
navigate: async ({ session }) => {
14+
const currentTask = session.currentTask;
15+
if (currentTask) {
16+
await router.push(`/onboarding/${currentTask.key}`)
17+
return;
18+
}
19+
20+
await router.push('/dashboard')
21+
}
22+
});
23+
```

.changeset/warm-rocks-flow.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/tanstack-react-start': minor
3+
'@clerk/react-router': minor
4+
'@clerk/nextjs': minor
5+
'@clerk/clerk-react': minor
6+
'@clerk/remix': minor
7+
'@clerk/vue': minor
8+
---
9+
10+
Rename `RedirectToTask` control component to `RedirectToTasks`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
8383
await u.po.signIn.enterTestOtpCode();
8484

8585
// Resolves task
86-
await u.po.signIn.waitForMounted();
86+
await u.po.signUp.waitForMounted();
8787
const fakeOrganization = Object.assign(u.services.organizations.createFakeOrganization(), {
8888
slug: u.services.organizations.createFakeOrganization().slug + '-with-sign-in-sso',
8989
});

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

Lines changed: 25 additions & 7 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,7 +32,16 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
2332
test.afterAll(async () => {
2433
const u = createTestUtils({ app });
2534
await u.services.organizations.deleteAll();
26-
await fakeUser.deleteIfExists();
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+
2745
await app.teardown();
2846
});
2947

@@ -38,8 +56,8 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
3856
const u = createTestUtils({ app, page, context });
3957
await u.po.signUp.goTo();
4058
await u.po.signUp.signUpWithEmailAndPassword({
41-
email: fakeUser.email,
42-
password: fakeUser.password,
59+
email: regularFakeUser.email,
60+
password: regularFakeUser.password,
4361
});
4462
await u.po.expect.toBeSignedIn();
4563

@@ -68,12 +86,12 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
6886
await u.po.signIn.getGoToSignUp().click();
6987

7088
await u.po.signUp.waitForMounted();
71-
await u.po.signUp.setEmailAddress(fakeUser.email);
89+
await u.po.signUp.setEmailAddress(fakeUserForOAuth.email);
7290
await u.po.signUp.continue();
7391
await u.po.signUp.enterTestOtpCode();
7492

7593
// Resolves task
76-
await u.po.signIn.waitForMounted();
94+
await u.po.signUp.waitForMounted();
7795
const fakeOrganization = Object.assign(u.services.organizations.createFakeOrganization(), {
7896
slug: u.services.organizations.createFakeOrganization().slug + '-with-sign-in-sso',
7997
});

packages/clerk-js/bundlewatch.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"files": [
3-
{ "path": "./dist/clerk.js", "maxSize": "622.25KB" },
4-
{ "path": "./dist/clerk.browser.js", "maxSize": "76KB" },
3+
{ "path": "./dist/clerk.js", "maxSize": "625KB" },
4+
{ "path": "./dist/clerk.browser.js", "maxSize": "78KB" },
55
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "117KB" },
6-
{ "path": "./dist/clerk.headless*.js", "maxSize": "58KB" },
6+
{ "path": "./dist/clerk.headless*.js", "maxSize": "61KB" },
77
{ "path": "./dist/ui-common*.js", "maxSize": "113KB" },
88
{ "path": "./dist/ui-common*.legacy.*.js", "maxSize": "118KB" },
99
{ "path": "./dist/vendors*.js", "maxSize": "40.2KB" },

0 commit comments

Comments
 (0)