-
Notifications
You must be signed in to change notification settings - Fork 435
feat(react-router): Add support for keyless mode #7794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a659eaf
feat(react-router): Keyless support
wobsoriano e08192c
chore: clean up
wobsoriano 140ba30
chore: clean up var name
wobsoriano 6bc3243
chore: remove any assertion
wobsoriano 15d5fc0
Merge branch 'main' into rob/react-router-keyless
wobsoriano 6638d89
chore: throw only if not keyless mode
wobsoriano fe7577e
add integraiton test
wobsoriano 4a6b959
chore: extract shared test utils
wobsoriano f79def9
chore: add changeset
wobsoriano 9354709
chore: share main keyless fallback function
wobsoriano ae6c168
chore: delete md file
wobsoriano 9e962c2
Merge branch 'main' into rob/react-router-keyless
wobsoriano 818352a
chore: extract reusable file storage create function
wobsoriano 57a8049
Add Keyless quickstart and refactor createFileStorage
wobsoriano 834c6eb
chore: revert
wobsoriano 069aaef
Merge branch 'main' into rob/react-router-keyless
wobsoriano 32bec51
chore: Make resolveKeysWithKeylessFallback function a method on the k…
wobsoriano 9fee85e
Merge branch 'main' into rob/react-router-keyless
wobsoriano a70b8a2
Merge branch 'main' into rob/react-router-keyless
wobsoriano 1c39d21
fix(repo): Handle framework query param in keyless claim URLs integra…
wobsoriano 6b04f9f
chore: share main keyless fallback function
wobsoriano 567b5a5
refactor: use shared helper for Next.js keyless test
wobsoriano 7183175
Merge branch 'main' into rob/react-router-keyless
wobsoriano 0049b7f
delete doc
wobsoriano 2e71569
chore: add missing framework requirement
wobsoriano ab36fa8
chore: remove redundant export
wobsoriano cda1649
fix type errors
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@clerk/react-router": minor | ||
| --- | ||
|
|
||
| Introduce Keyless quickstart for React Router. This allows the Clerk SDK to be used without having to sign up and paste your keys manually. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import type { BrowserContext, Page } from '@playwright/test'; | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| import type { Application } from '../models/application'; | ||
| import { createTestUtils } from './index'; | ||
|
|
||
| /** | ||
| * Mocks the environment API call to return a claimed instance. | ||
| * Used in keyless mode tests to simulate an instance that has been claimed. | ||
| */ | ||
| export const mockClaimedInstanceEnvironmentCall = async (page: Page): Promise<void> => { | ||
| await page.route('*/**/v1/environment*', async route => { | ||
| const response = await route.fetch(); | ||
| const json = await response.json(); | ||
| const newJson = { | ||
| ...json, | ||
| auth_config: { | ||
| ...json.auth_config, | ||
| claimed_at: Date.now(), | ||
| }, | ||
| }; | ||
| await route.fulfill({ response, json: newJson }); | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Tests that the keyless popover can be toggled and the claim link opens the dashboard. | ||
| */ | ||
| export async function testToggleCollapsePopoverAndClaim({ | ||
| page, | ||
| context, | ||
| app, | ||
| dashboardUrl, | ||
| }: { | ||
| page: Page; | ||
| context: BrowserContext; | ||
| app: Application; | ||
| dashboardUrl: string; | ||
| }): Promise<void> { | ||
| const u = createTestUtils({ app, page, context }); | ||
| await u.page.goToAppHome(); | ||
| await u.page.waitForClerkJsLoaded(); | ||
| await u.po.expect.toBeSignedOut(); | ||
|
|
||
| await u.po.keylessPopover.waitForMounted(); | ||
|
|
||
| expect(await u.po.keylessPopover.isExpanded()).toBe(false); | ||
| await u.po.keylessPopover.toggle(); | ||
| expect(await u.po.keylessPopover.isExpanded()).toBe(true); | ||
|
|
||
| const claim = u.po.keylessPopover.promptsToClaim(); | ||
|
|
||
| const [newPage] = await Promise.all([context.waitForEvent('page'), claim.click()]); | ||
|
|
||
| await newPage.waitForLoadState(); | ||
|
|
||
| await newPage.waitForURL(url => { | ||
| const urlToReturnTo = `${dashboardUrl}apps/claim?token=`; | ||
|
|
||
| const signUpForceRedirectUrl = url.searchParams.get('sign_up_force_redirect_url'); | ||
|
|
||
| const signUpForceRedirectUrlCheck = | ||
| signUpForceRedirectUrl?.startsWith(urlToReturnTo) || | ||
| (signUpForceRedirectUrl?.startsWith(`${dashboardUrl}prepare-account`) && | ||
| signUpForceRedirectUrl?.includes(encodeURIComponent('apps/claim?token='))); | ||
|
|
||
| return ( | ||
| url.pathname === '/apps/claim/sign-in' && | ||
| url.searchParams.get('sign_in_force_redirect_url')?.startsWith(urlToReturnTo) && | ||
| signUpForceRedirectUrlCheck | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that a claimed application with missing explicit keys shows the popover expanded | ||
| * with a prompt to get keys from the dashboard. | ||
| */ | ||
| export async function testClaimedAppWithMissingKeys({ | ||
| page, | ||
| context, | ||
| app, | ||
| dashboardUrl, | ||
| }: { | ||
| page: Page; | ||
| context: BrowserContext; | ||
| app: Application; | ||
| dashboardUrl: string; | ||
| }): Promise<void> { | ||
| await mockClaimedInstanceEnvironmentCall(page); | ||
| const u = createTestUtils({ app, page, context }); | ||
| await u.page.goToAppHome(); | ||
| await u.page.waitForClerkJsLoaded(); | ||
|
|
||
| await u.po.keylessPopover.waitForMounted(); | ||
| expect(await u.po.keylessPopover.isExpanded()).toBe(true); | ||
| await expect(u.po.keylessPopover.promptToUseClaimedKeys()).toBeVisible(); | ||
|
|
||
| const [newPage] = await Promise.all([ | ||
| context.waitForEvent('page'), | ||
| u.po.keylessPopover.promptToUseClaimedKeys().click(), | ||
| ]); | ||
|
|
||
| await newPage.waitForLoadState(); | ||
| await newPage.waitForURL(url => { | ||
| return url.href.startsWith(`${dashboardUrl}sign-in?redirect_url=${encodeURIComponent(dashboardUrl)}apps%2Fapp_`); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that the keyless popover is removed after adding keys to .env and restarting the dev server. | ||
| */ | ||
| export async function testKeylessRemovedAfterEnvAndRestart({ | ||
| page, | ||
| context, | ||
| app, | ||
| }: { | ||
| page: Page; | ||
| context: BrowserContext; | ||
| app: Application; | ||
| }): Promise<void> { | ||
| const u = createTestUtils({ app, page, context }); | ||
| await u.page.goToAppHome(); | ||
|
|
||
| await u.po.keylessPopover.waitForMounted(); | ||
| expect(await u.po.keylessPopover.isExpanded()).toBe(false); | ||
|
|
||
| // Copy keys from keyless.json to .env | ||
| await app.keylessToEnv(); | ||
|
|
||
| // Restart the dev server to pick up new env vars (Vite doesn't hot-reload .env) | ||
| await app.restart(); | ||
|
|
||
| await u.page.goToAppHome(); | ||
|
|
||
| // Keyless popover should no longer be present since we now have explicit keys | ||
| await u.po.keylessPopover.waitForUnmounted(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { test } from '@playwright/test'; | ||
|
|
||
| import type { Application } from '../../models/application'; | ||
| import { appConfigs } from '../../presets'; | ||
| import { | ||
| testClaimedAppWithMissingKeys, | ||
| testKeylessRemovedAfterEnvAndRestart, | ||
| testToggleCollapsePopoverAndClaim, | ||
| } from '../../testUtils/keylessHelpers'; | ||
|
|
||
| const commonSetup = appConfigs.reactRouter.reactRouterNode.clone(); | ||
|
|
||
| test.describe('Keyless mode @react-router', () => { | ||
| test.describe.configure({ mode: 'serial' }); | ||
| test.setTimeout(90_000); | ||
|
|
||
| test.use({ | ||
| extraHTTPHeaders: { | ||
| 'x-vercel-protection-bypass': process.env.VERCEL_AUTOMATION_BYPASS_SECRET || '', | ||
| }, | ||
| }); | ||
|
|
||
| let app: Application; | ||
| let dashboardUrl = 'https://dashboard.clerk.com/'; | ||
|
|
||
| test.beforeAll(async () => { | ||
| app = await commonSetup.commit(); | ||
| await app.setup(); | ||
| await app.withEnv(appConfigs.envs.withKeyless); | ||
| if (appConfigs.envs.withKeyless.privateVariables.get('CLERK_API_URL')?.includes('clerkstage')) { | ||
| dashboardUrl = 'https://dashboard.clerkstage.dev/'; | ||
| } | ||
| await app.dev(); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| // Keep files for debugging | ||
| await app?.teardown(); | ||
| }); | ||
|
|
||
| test('Toggle collapse popover and claim.', async ({ page, context }) => { | ||
| await testToggleCollapsePopoverAndClaim({ page, context, app, dashboardUrl }); | ||
| }); | ||
|
|
||
| test('Lands on claimed application with missing explicit keys, expanded by default, click to get keys from dashboard.', async ({ | ||
| page, | ||
| context, | ||
| }) => { | ||
| await testClaimedAppWithMissingKeys({ page, context, app, dashboardUrl }); | ||
| }); | ||
|
|
||
| test('Keyless popover is removed after adding keys to .env and restarting.', async ({ page, context }) => { | ||
| await testKeylessRemovedAfterEnvAndRestart({ page, context, app }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.