Skip to content

Commit

Permalink
fix(*): Improve backend types and drop user, organization and session…
Browse files Browse the repository at this point in the history
… from AuthObject (#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 (#2384)"

This reverts commit bbb9b66.
  • Loading branch information
nikosdouvlis authored Dec 18, 2023
1 parent 87e04d8 commit 35f406e
Show file tree
Hide file tree
Showing 40 changed files with 338 additions and 412 deletions.
5 changes: 0 additions & 5 deletions .changeset/many-gifts-swim.md

This file was deleted.

2 changes: 2 additions & 0 deletions .changeset/metal-wolves-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion integration/presets/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const appRouter = applicationConfig()
.setName('next-app-router')
.useTemplate(templates['next-app-router'])
.setEnvFormatter('public', key => `NEXT_PUBLIC_${key}`)
.addScript('setup', 'npm i --prefer-offline')
.addScript('setup', 'npm i')
.addScript('dev', 'npm run dev')
.addScript('build', 'npm run build')
.addScript('serve', 'npm run start')
Expand Down
2 changes: 1 addition & 1 deletion integration/presets/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const cra = applicationConfig()
.setName('react-cra')
.useTemplate(templates['react-cra'])
.setEnvFormatter('public', key => `REACT_APP_${key}`)
.addScript('setup', 'npm i --prefer-offline')
.addScript('setup', 'npm i')
.addScript('dev', 'npm run start')
.addScript('build', 'npm run build')
.addScript('serve', 'npm run start')
Expand Down
5 changes: 0 additions & 5 deletions integration/templates/next-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
"start": "next start"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/clerk-react": "file:.yalc/@clerk/clerk-react",
"@clerk/nextjs": "file:.yalc/@clerk/nextjs",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
"@types/node": "^18.17.0",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
Expand Down
1 change: 0 additions & 1 deletion integration/tests/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { appConfigs } from '../presets';
import { fs, parseEnvOptions, startClerkJsHttpServer } from '../scripts';

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

await startClerkJsHttpServer();
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.describe('navigation modes @generic', () => {
.addFile(
'src/app/provider.tsx',
() => `'use client'
import { ClerkProvider } from "@clerk/nextjs"
import { ClerkProvider } from "@clerk/nextjs";
export function Provider({ children }: { children: any }) {
return (
Expand Down
1 change: 0 additions & 1 deletion integration/tests/next-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { appConfigs } from '../presets';
test.describe('next build @nextjs', () => {
test.describe.configure({ mode: 'parallel' });
let app: Application;
const output = [];

test.beforeAll(async () => {
app = await appConfigs.next.appRouter
Expand Down
95 changes: 49 additions & 46 deletions integration/tests/sign-in-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,52 @@ import { appConfigs } from '../presets';
import type { FakeUser } from '../testUtils';
import { createTestUtils, testAgainstRunningApps } from '../testUtils';

testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign in smoke test @generic', ({ app }) => {
test.describe.configure({ mode: 'serial' });

let fakeUser: FakeUser;

test.beforeAll(async () => {
const u = createTestUtils({ app });
fakeUser = u.services.users.createFakeUser();
await u.services.users.createBapiUser(fakeUser);
});

test.afterAll(async () => {
await fakeUser.deleteIfExists();
await app.teardown();
});

test('sign in with email and password', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.setIdentifier(fakeUser.email);
await u.po.signIn.continue();
await u.po.signIn.setPassword(fakeUser.password);
await u.po.signIn.continue();
await u.po.expect.toBeSignedIn();
});

test('sign in with email and instant password', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.expect.toBeSignedIn();
await u.page.pause();
});

test('access protected page @express', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.expect.toBeSignedIn();

expect(await u.page.locator("data-test-id='protected-api-response'").count()).toEqual(0);
await u.page.goToRelative('/protected');
await u.page.isVisible("data-test-id='protected-api-response'");
await u.page.pause();
});
});
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
'sign in smoke test @generic @nextjs',
({ app }) => {
test.describe.configure({ mode: 'serial' });

let fakeUser: FakeUser;

test.beforeAll(async () => {
const u = createTestUtils({ app });
fakeUser = u.services.users.createFakeUser();
await u.services.users.createBapiUser(fakeUser);
});

test.afterAll(async () => {
await fakeUser.deleteIfExists();
await app.teardown();
});

test('sign in with email and password', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.setIdentifier(fakeUser.email);
await u.po.signIn.continue();
await u.po.signIn.setPassword(fakeUser.password);
await u.po.signIn.continue();
await u.po.expect.toBeSignedIn();
});

test('sign in with email and instant password', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.expect.toBeSignedIn();
await u.page.pause();
});

test('access protected page @express', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.expect.toBeSignedIn();

expect(await u.page.locator("data-test-id='protected-api-response'").count()).toEqual(0);
await u.page.goToRelative('/protected');
await u.page.isVisible("data-test-id='protected-api-response'");
await u.page.pause();
});
},
);
Loading

0 comments on commit 35f406e

Please sign in to comment.