-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js): Add experimental combined flow (#4607)
Co-authored-by: Dylan Staley <88163+dstaley@users.noreply.github.com> Co-authored-by: Bryce Kalow <bryce@clerk.dev>
- Loading branch information
1 parent
6fdffaf
commit 550c7e9
Showing
60 changed files
with
703 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
--- | ||
'@clerk/localizations': patch | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduce experimental sign-in combined flow. |
This file contains 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 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 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 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 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,160 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
import { appConfigs } from '../presets'; | ||
import { createTestUtils, type FakeUser, testAgainstRunningApps } from '../testUtils'; | ||
|
||
testAgainstRunningApps({ withEnv: [appConfigs.envs.withCombinedFlow] })('combined sign in flow @nextjs', ({ app }) => { | ||
test.describe.configure({ mode: 'serial' }); | ||
|
||
let fakeUser: FakeUser; | ||
|
||
test.beforeAll(async () => { | ||
const u = createTestUtils({ app }); | ||
fakeUser = u.services.users.createFakeUser({ | ||
withPhoneNumber: true, | ||
withUsername: true, | ||
}); | ||
await u.services.users.createBapiUser(fakeUser); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await fakeUser.deleteIfExists(); | ||
await app.teardown(); | ||
}); | ||
|
||
test('flows are combined', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
await u.po.signIn.goTo(); | ||
|
||
await expect(u.page.getByText(`Don’t have an account?`)).toBeHidden(); | ||
}); | ||
|
||
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(); | ||
}); | ||
|
||
test('sign in with email code', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUser.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.getUseAnotherMethodLink().click(); | ||
await u.po.signIn.getAltMethodsEmailCodeButton().click(); | ||
await u.po.signIn.enterTestOtpCode(); | ||
await u.po.expect.toBeSignedIn(); | ||
}); | ||
|
||
test('sign in with phone number and password', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.usePhoneNumberIdentifier().click(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUser.phoneNumber); | ||
await u.po.signIn.setPassword(fakeUser.password); | ||
await u.po.signIn.continue(); | ||
await u.po.expect.toBeSignedIn(); | ||
}); | ||
|
||
test('sign in only with phone number', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
const fakeUserWithoutPassword = u.services.users.createFakeUser({ | ||
fictionalEmail: true, | ||
withPassword: false, | ||
withPhoneNumber: true, | ||
}); | ||
await u.services.users.createBapiUser(fakeUserWithoutPassword); | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.usePhoneNumberIdentifier().click(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUserWithoutPassword.phoneNumber); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.enterTestOtpCode(); | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
await fakeUserWithoutPassword.deleteIfExists(); | ||
}); | ||
|
||
test('sign in with username and password', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUser.username); | ||
await u.po.signIn.setPassword(fakeUser.password); | ||
await u.po.signIn.continue(); | ||
await u.po.expect.toBeSignedIn(); | ||
}); | ||
|
||
test('can reset password', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
const fakeUserWithPasword = u.services.users.createFakeUser({ | ||
fictionalEmail: true, | ||
withPassword: true, | ||
}); | ||
await u.services.users.createBapiUser(fakeUserWithPasword); | ||
|
||
await u.po.signIn.goTo(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUserWithPasword.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.getForgotPassword().click(); | ||
await u.po.signIn.getResetPassword().click(); | ||
await u.po.signIn.enterTestOtpCode(); | ||
await u.po.signIn.setPassword(`${fakeUserWithPasword.password}_reset`); | ||
await u.po.signIn.setPasswordConfirmation(`${fakeUserWithPasword.password}_reset`); | ||
await u.po.signIn.getResetPassword().click(); | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
await fakeUserWithPasword.deleteIfExists(); | ||
}); | ||
|
||
test('cannot sign in with wrong password', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
|
||
await u.po.signIn.goTo(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUser.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.setPassword('wrong-password'); | ||
await u.po.signIn.continue(); | ||
await expect(u.page.getByText(/^password is incorrect/i)).toBeVisible(); | ||
|
||
await u.po.expect.toBeSignedOut(); | ||
}); | ||
|
||
test('cannot sign in with wrong password but can sign in with email', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
|
||
await u.po.signIn.goTo(); | ||
await u.po.signIn.getIdentifierInput().fill(fakeUser.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.setPassword('wrong-password'); | ||
await u.po.signIn.continue(); | ||
|
||
await expect(u.page.getByText(/^password is incorrect/i)).toBeVisible(); | ||
|
||
await u.po.signIn.getUseAnotherMethodLink().click(); | ||
await u.po.signIn.getAltMethodsEmailCodeButton().click(); | ||
await u.po.signIn.enterTestOtpCode(); | ||
|
||
await u.po.expect.toBeSignedIn(); | ||
}); | ||
|
||
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'"); | ||
}); | ||
}); |
This file contains 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,118 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
import { appConfigs } from '../presets'; | ||
import { createTestUtils, testAgainstRunningApps } from '../testUtils'; | ||
|
||
testAgainstRunningApps({ withEnv: [appConfigs.envs.withCombinedFlow] })('combined sign up flow @nextjs', ({ app }) => { | ||
test.describe.configure({ mode: 'serial' }); | ||
|
||
test.afterAll(async () => { | ||
await app.teardown(); | ||
}); | ||
|
||
test('sign up with email and password', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
const fakeUser = u.services.users.createFakeUser({ | ||
fictionalEmail: true, | ||
withPassword: true, | ||
}); | ||
|
||
// Go to sign in page | ||
await u.po.signIn.goTo(); | ||
|
||
// Fill in sign in form | ||
await u.po.signIn.setIdentifier(fakeUser.email); | ||
await u.po.signIn.continue(); | ||
|
||
// Verify email | ||
await u.po.signUp.enterTestOtpCode(); | ||
|
||
await u.page.waitForAppUrl('/sign-in/create/continue'); | ||
|
||
await u.po.signUp.setPassword(fakeUser.password); | ||
await u.po.signUp.continue(); | ||
|
||
// Check if user is signed in | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
await fakeUser.deleteIfExists(); | ||
}); | ||
|
||
test('sign up with username, email, and password', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
const fakeUser = u.services.users.createFakeUser({ | ||
fictionalEmail: true, | ||
withPassword: true, | ||
withUsername: true, | ||
}); | ||
|
||
await u.po.signIn.goTo(); | ||
await u.po.signIn.setIdentifier(fakeUser.username); | ||
await u.po.signIn.continue(); | ||
await u.page.waitForAppUrl('/sign-in/create'); | ||
|
||
const prefilledUsername = await u.po.signUp.getUsernameInput().inputValue(); | ||
expect(prefilledUsername).toBe(fakeUser.username); | ||
|
||
await u.po.signUp.setEmailAddress(fakeUser.email); | ||
await u.po.signUp.setPassword(fakeUser.password); | ||
await u.po.signUp.continue(); | ||
|
||
await u.po.signUp.enterTestOtpCode(); | ||
|
||
await u.po.expect.toBeSignedIn(); | ||
|
||
await fakeUser.deleteIfExists(); | ||
}); | ||
|
||
test('sign up, sign out and sign in again', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
const fakeUser = u.services.users.createFakeUser({ | ||
fictionalEmail: true, | ||
withPhoneNumber: true, | ||
withUsername: true, | ||
}); | ||
|
||
// Go to sign in page | ||
await u.po.signIn.goTo(); | ||
|
||
// Fill in sign in form | ||
await u.po.signIn.setIdentifier(fakeUser.email); | ||
await u.po.signIn.continue(); | ||
|
||
// Verify email | ||
await u.po.signUp.enterTestOtpCode(); | ||
|
||
await u.page.waitForAppUrl('/sign-in/create/continue'); | ||
|
||
await u.po.signUp.setPassword(fakeUser.password); | ||
await u.po.signUp.continue(); | ||
|
||
// Check if user is signed in | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
// Toggle user button | ||
await u.po.userButton.toggleTrigger(); | ||
await u.po.userButton.waitForPopover(); | ||
|
||
// Click sign out | ||
await u.po.userButton.triggerSignOut(); | ||
|
||
// Check if user is signed out | ||
await u.po.expect.toBeSignedOut(); | ||
|
||
// Go to sign in page | ||
await u.po.signIn.goTo(); | ||
|
||
// Fill in sign in form | ||
await u.po.signIn.signInWithEmailAndInstantPassword({ | ||
email: fakeUser.email, | ||
password: fakeUser.password, | ||
}); | ||
|
||
// Check if user is signed in | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
await fakeUser.deleteIfExists(); | ||
}); | ||
}); |
This file contains 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 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.