Skip to content

Commit

Permalink
Merge branch 'main' into locale-update
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraBeatris authored Jun 4, 2024
2 parents 49cc072 + 3c2b666 commit 6a92086
Show file tree
Hide file tree
Showing 68 changed files with 790 additions and 6,548 deletions.
36 changes: 36 additions & 0 deletions .changeset/calm-wasps-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
'@clerk/clerk-expo': minor
---

Introduce `getClerkInstance()` to avoid importing the Clerk class from clerk-js manually.

This enables developers to create and access a Clerk instance in their application outside of React.
```tsx
import { ClerkProvider, getClerkInstance } from "@clerk/expo"

const clerkInstance = getClerkInstance({ publishableKey: 'xxxx' })

// Always pass the `publishableKey` to `ClerkProvider`
<ClerkProvider publishableKey={'xxxx'}>
...
</ClerkProvider>

// Somewhere in your code, outside of React you can do
const token = await clerkInstance.session?.getToken();
fetch('http://example.com/', {headers: {Authorization: token })
```
```tsx
import { ClerkProvider, getClerkInstance } from "@clerk/expo"

// Always pass the `publishableKey` to `ClerkProvider`
<ClerkProvider publishableKey={'xxxx'}>
...
</ClerkProvider>

// If you sure that this code will run after the ClerkProvider has rendered then you can use `getClerkIntance` without options
const token = await getClerkInstance().session?.getToken();
fetch('http://example.com/', {headers: {Authorization: token })

```
Attention: If `getClerkInstance` is called without a publishable key, and ClerkProvider has not rendered yet, an error will be thrown
2 changes: 2 additions & 0 deletions .changeset/dirty-panthers-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/empty-deers-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/shared": patch
---

Update `js-cookie` from `3.0.1` to `3.0.5`. Update `swr` from `2.2.0` to `2.2.5`.
2 changes: 2 additions & 0 deletions .changeset/gentle-brooms-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/giant-cougars-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/metal-foxes-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-react': patch
---

Update `SignUpButton` and `SignInButton` to respect `forceRedirect` and `fallbackRedirect` props. Previously, these were getting ignored and successful completions of the flows would fallback to the default redirect URL.
3 changes: 3 additions & 0 deletions .changeset/pretty-hounds-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
---

2 changes: 2 additions & 0 deletions .changeset/rotten-eyes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/sixty-ears-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fixed a bug where Clerk components rendered in modals were wrapped with `aria-hidden`.
2 changes: 2 additions & 0 deletions .changeset/yellow-deers-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
4 changes: 2 additions & 2 deletions integration/templates/express-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"ejs": "^3.1.6",
"express": "^4.18.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.3",
"typescript": "^5.4.5",
"vite-express": "^0.11.0"
},
"devDependencies": {
"@types/express": "^4.17.15",
"@types/express": "^4.17.21",
"@types/node": "^18.19.33",
"nodemon": "^2.0.20",
"vite": "^4.0.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"next": "14.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5"
"typescript": "^5.4.5"
},
"engines": {
"node": ">=18.17.0"
Expand Down
2 changes: 1 addition & 1 deletion integration/templates/next-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"next": "^13.5",
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "5.1.6"
"typescript": "^5.4.5"
},
"engines": {
"node": ">=18.17.0"
Expand Down
35 changes: 35 additions & 0 deletions integration/templates/next-app-router/src/app/buttons/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { SignInButton, SignUpButton } from '@clerk/nextjs';

export default function Home() {
return (
<main>
<SignInButton
mode='modal'
forceRedirectUrl='/protected'
>
Sign in button (force)
</SignInButton>

<SignInButton
mode='modal'
fallbackRedirectUrl='/protected'
>
Sign in button (fallback)
</SignInButton>

<SignUpButton
mode='modal'
forceRedirectUrl='/protected'
>
Sign up button (force)
</SignUpButton>

<SignUpButton
mode='modal'
fallbackRedirectUrl='/protected'
>
Sign up button (fallback)
</SignUpButton>
</main>
);
}
2 changes: 1 addition & 1 deletion integration/templates/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"typescript": "^5.0.2",
"typescript": "^5.4.5",
"vite": "^4.3.9"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion integration/templates/remix-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"eslint": "^8.38.0",
"typescript": "^5.0.4"
"typescript": "^5.4.5"
},
"engines": {
"node": ">=18.17.0"
Expand Down
130 changes: 130 additions & 0 deletions integration/tests/redirects.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { test } from '@playwright/test';

import { appConfigs } from '../presets';
import type { FakeUser } from '../testUtils';
import { createTestUtils, testAgainstRunningApps } from '../testUtils';

testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('redirect props @nextjs', ({ app }) => {
test.describe.configure({ mode: 'serial' });

let fakeUser: FakeUser;

test.beforeAll(async () => {
const u = createTestUtils({ app });
fakeUser = u.services.users.createFakeUser({
fictionalEmail: true,
withPhoneNumber: true,
withUsername: true,
});
await u.services.users.createBapiUser(fakeUser);
});

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

test.afterEach(async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.signOut();
await u.page.context().clearCookies();
});

test.describe('SignInButton', () => {
test('sign in button respects forceRedirectUrl', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });

await u.page.goToRelative('/buttons');
await u.page.waitForClerkJsLoaded();
await u.po.expect.toBeSignedOut();

await u.page.getByText('Sign in button (force)').click();

await u.po.signIn.waitForMounted();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });

await u.page.waitForAppUrl('/protected');

await u.po.expect.toBeSignedIn();
});

test('sign in button respects fallbackRedirectUrl', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });

await u.page.goToRelative('/buttons');
await u.page.waitForClerkJsLoaded();
await u.po.expect.toBeSignedOut();

await u.page.getByText('Sign in button (fallback)').click();

await u.po.signIn.waitForMounted();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });

await u.page.waitForAppUrl('/protected');

await u.po.expect.toBeSignedIn();
});
});

test.describe('SignUpButton', () => {
test('sign up button respects forceRedirectUrl', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
const fakeUser = u.services.users.createFakeUser({
fictionalEmail: true,
withPhoneNumber: true,
withUsername: true,
});

await u.page.goToRelative('/buttons');
await u.page.waitForClerkJsLoaded();

await u.page.getByText('Sign up button (force)').click();

// Fill in sign up form
await u.po.signUp.signUpWithEmailAndPassword({
email: fakeUser.email,
password: fakeUser.password,
});

// Verify email
await u.po.signUp.enterTestOtpCode();

await u.page.waitForAppUrl('/protected');

// Check if user is signed in
await u.po.expect.toBeSignedIn();

await fakeUser.deleteIfExists();
});

test('sign up button respects fallbackRedirectUrl', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
const fakeUser = u.services.users.createFakeUser({
fictionalEmail: true,
withPhoneNumber: true,
withUsername: true,
});

await u.page.goToRelative('/buttons');
await u.page.waitForClerkJsLoaded();

await u.page.getByText('Sign up button (fallback)').click();

// Fill in sign up form
await u.po.signUp.signUpWithEmailAndPassword({
email: fakeUser.email,
password: fakeUser.password,
});

// Verify email
await u.po.signUp.enterTestOtpCode();

await u.page.waitForAppUrl('/protected');

// Check if user is signed in
await u.po.expect.toBeSignedIn();

await fakeUser.deleteIfExists();
});
});
});
Loading

0 comments on commit 6a92086

Please sign in to comment.