Skip to content

Commit 35f406e

Browse files
authored
fix(*): Improve backend types and drop user, organization and session from AuthObject (clerk#2373)
* fix(nextjs): Fix Protect type * feat(backend): Add top-level file-based modules to support TS moduleResolution set to "node" * feat(backend): Drop user, organization and session from AuthObject * feat(nextjs): Simplify auth().protect() types * fix(backend): Fix unit tests * fix(backend): Rewrite decorateObjectWithResources for clarity * Revert "chore(shared): Upgrade swr to 2.2.4 (clerk#2384)" This reverts commit bbb9b66.
1 parent 87e04d8 commit 35f406e

40 files changed

Lines changed: 338 additions & 412 deletions

.changeset/many-gifts-swim.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/metal-wolves-wave.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/presets/next.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const appRouter = applicationConfig()
77
.setName('next-app-router')
88
.useTemplate(templates['next-app-router'])
99
.setEnvFormatter('public', key => `NEXT_PUBLIC_${key}`)
10-
.addScript('setup', 'npm i --prefer-offline')
10+
.addScript('setup', 'npm i')
1111
.addScript('dev', 'npm run dev')
1212
.addScript('build', 'npm run build')
1313
.addScript('serve', 'npm run start')

integration/presets/react.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const cra = applicationConfig()
99
.setName('react-cra')
1010
.useTemplate(templates['react-cra'])
1111
.setEnvFormatter('public', key => `REACT_APP_${key}`)
12-
.addScript('setup', 'npm i --prefer-offline')
12+
.addScript('setup', 'npm i')
1313
.addScript('dev', 'npm run start')
1414
.addScript('build', 'npm run build')
1515
.addScript('serve', 'npm run start')

integration/templates/next-app-router/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
"start": "next start"
1010
},
1111
"dependencies": {
12-
"@clerk/backend": "file:.yalc/@clerk/backend",
13-
"@clerk/clerk-react": "file:.yalc/@clerk/clerk-react",
14-
"@clerk/nextjs": "file:.yalc/@clerk/nextjs",
15-
"@clerk/shared": "file:.yalc/@clerk/shared",
16-
"@clerk/types": "file:.yalc/@clerk/types",
1712
"@types/node": "^18.17.0",
1813
"@types/react": "18.2.14",
1914
"@types/react-dom": "18.2.6",

integration/tests/global.setup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { appConfigs } from '../presets';
55
import { fs, parseEnvOptions, startClerkJsHttpServer } from '../scripts';
66

77
setup('start long running apps', async () => {
8-
await fs.remove(constants.TMP_DIR);
98
await fs.ensureDir(constants.TMP_DIR);
109

1110
await startClerkJsHttpServer();

integration/tests/navigation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test.describe('navigation modes @generic', () => {
1616
.addFile(
1717
'src/app/provider.tsx',
1818
() => `'use client'
19-
import { ClerkProvider } from "@clerk/nextjs"
19+
import { ClerkProvider } from "@clerk/nextjs";
2020
2121
export function Provider({ children }: { children: any }) {
2222
return (

integration/tests/next-build.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { appConfigs } from '../presets';
66
test.describe('next build @nextjs', () => {
77
test.describe.configure({ mode: 'parallel' });
88
let app: Application;
9-
const output = [];
109

1110
test.beforeAll(async () => {
1211
app = await appConfigs.next.appRouter

integration/tests/sign-in-smoke.test.ts

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,52 @@ import { appConfigs } from '../presets';
44
import type { FakeUser } from '../testUtils';
55
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
66

7-
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign in smoke test @generic', ({ app }) => {
8-
test.describe.configure({ mode: 'serial' });
9-
10-
let fakeUser: FakeUser;
11-
12-
test.beforeAll(async () => {
13-
const u = createTestUtils({ app });
14-
fakeUser = u.services.users.createFakeUser();
15-
await u.services.users.createBapiUser(fakeUser);
16-
});
17-
18-
test.afterAll(async () => {
19-
await fakeUser.deleteIfExists();
20-
await app.teardown();
21-
});
22-
23-
test('sign in with email and password', async ({ page, context }) => {
24-
const u = createTestUtils({ app, page, context });
25-
await u.po.signIn.goTo();
26-
await u.po.signIn.setIdentifier(fakeUser.email);
27-
await u.po.signIn.continue();
28-
await u.po.signIn.setPassword(fakeUser.password);
29-
await u.po.signIn.continue();
30-
await u.po.expect.toBeSignedIn();
31-
});
32-
33-
test('sign in with email and instant password', async ({ page, context }) => {
34-
const u = createTestUtils({ app, page, context });
35-
await u.po.signIn.goTo();
36-
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
37-
await u.po.expect.toBeSignedIn();
38-
await u.page.pause();
39-
});
40-
41-
test('access protected page @express', async ({ page, context }) => {
42-
const u = createTestUtils({ app, page, context });
43-
await u.po.signIn.goTo();
44-
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
45-
await u.po.expect.toBeSignedIn();
46-
47-
expect(await u.page.locator("data-test-id='protected-api-response'").count()).toEqual(0);
48-
await u.page.goToRelative('/protected');
49-
await u.page.isVisible("data-test-id='protected-api-response'");
50-
await u.page.pause();
51-
});
52-
});
7+
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
8+
'sign in smoke test @generic @nextjs',
9+
({ app }) => {
10+
test.describe.configure({ mode: 'serial' });
11+
12+
let fakeUser: FakeUser;
13+
14+
test.beforeAll(async () => {
15+
const u = createTestUtils({ app });
16+
fakeUser = u.services.users.createFakeUser();
17+
await u.services.users.createBapiUser(fakeUser);
18+
});
19+
20+
test.afterAll(async () => {
21+
await fakeUser.deleteIfExists();
22+
await app.teardown();
23+
});
24+
25+
test('sign in with email and password', async ({ page, context }) => {
26+
const u = createTestUtils({ app, page, context });
27+
await u.po.signIn.goTo();
28+
await u.po.signIn.setIdentifier(fakeUser.email);
29+
await u.po.signIn.continue();
30+
await u.po.signIn.setPassword(fakeUser.password);
31+
await u.po.signIn.continue();
32+
await u.po.expect.toBeSignedIn();
33+
});
34+
35+
test('sign in with email and instant password', async ({ page, context }) => {
36+
const u = createTestUtils({ app, page, context });
37+
await u.po.signIn.goTo();
38+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
39+
await u.po.expect.toBeSignedIn();
40+
await u.page.pause();
41+
});
42+
43+
test('access protected page @express', async ({ page, context }) => {
44+
const u = createTestUtils({ app, page, context });
45+
await u.po.signIn.goTo();
46+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
47+
await u.po.expect.toBeSignedIn();
48+
49+
expect(await u.page.locator("data-test-id='protected-api-response'").count()).toEqual(0);
50+
await u.page.goToRelative('/protected');
51+
await u.page.isVisible("data-test-id='protected-api-response'");
52+
await u.page.pause();
53+
});
54+
},
55+
);

0 commit comments

Comments
 (0)