Custom sign-in flow
An app that builds its own sign-in screen on the SDK's API sends an SMS code to an existing user and signs them in with it. No prebuilt view is involved, so the :e2e host has a small form of its own for this.
Sub-features
request-codeshows Clerk's error for a number no user holds.completesends the SMS code, shows the code field, verifies the code, activates the session, and returns to the home, which shows the user and the session.
How to get to it (user POV)
- Launch the app signed out and tap
Custom sign-in. The screen has a phone field andSend code, then a code field andVerify code.
Driving it with verify
Preconditions:
The standard settings turn the
phone_codestrategy on.upfails withINSTANCE_MISCONFIGUREDwhen the application does not show it.The spec seeds its own
+clerk_testuser withhost.seedUser({ phone: true }).Request the code. Run
e2e-tests/bin/control-clerk-android run custom-flow-sign-in/complete. Each test launches and tapse2e.home.customSignIn, whichcustomSignInLink(screen)inspecs/compose.tsfinds. The spec fillsverify.customSignIn.phoneNumberwith the user's phone, tapsverify.customSignIn.sendCode, and expectsverify.customSignIn.codeandverify.customSignIn.verifyCodewith noverify.customSignIn.error. The form shows the code field only whenClerk.auth.signInWithOtpreturned success. Screenshotcustom-code.Unknown number. Run
e2e-tests/bin/control-clerk-android run custom-flow-sign-in/request-code. It fills a number fromhost.newPhone(), which no user holds, and expectsverify.customSignIn.errorto readCouldn't find your account., with no code field. Screenshotcustom-error.Enter the code.
completethen typesCLERK_TEST_CODEand tapsverify.customSignIn.verifyCode, which callsSignIn.verifyCodeand thenClerk.auth.setActive. The host leaves the form only when both returned success, sohost.expectSignedInAs(user), which waits for the home to show the user's email, the seeded user ID, and a session ID, proves both. Screenshotcustom-signed-in.Proof. Both specs pass.
Gotchas
- The form trims what is typed and changes nothing else, so fill the whole number,
user.phone, with its+1. - A sign-in error shows in
verify.customSignIn.error, and the form stays on screen. - The host shows the form until the form reports that its sign-in succeeded. A session alone does not close it, because the SDK has an active session as soon as the code is verified, before
setActiveis called. Couldn't find your account.is Clerk's message for an identifier no user holds. It comes from the API, so a change of that wording failsrequest-code.- The screen keeps no state across launches. Every launch starts on the home, and the link opens the form on the phone field.