One call starts a sign-in. The client picks the method from the app's settings and the user's devices.
signInOrUp#
const { data, error } = await scute.signInOrUp("ada@example.com");Signs an existing user in, or creates the user when the identifier is new. The identifier is an email or a phone number.
How the method is picked:
- Passkey, when the app has passkeys_enabled: true, the browser supports WebAuthn, the user has a passkey, and this device holds one of the user's credentials. A passkey on another device counts as a new device and falls through to step 2.
- One-time code, when the identifier looks like a phone number or the app's email_auth_type is "otp".
- Magic link otherwise.
Pass { webauthn: "disabled" } to skip the passkey step.
signIn and signUp#
| Method | Behavior |
|---|---|
| signIn(identifier, options?) | Existing users only. Returns IdentifierNotRecognizedError for an unknown identifier. |
| signUp(identifier, options?) | New users only. Returns IdentifierAlreadyExistsError when a user with a verified email or phone exists. options.userMeta sets profile fields. |
| signInOrUp(identifier, options?) | Either. A new user goes through signUp without userMeta. |
await scute.signUp("ada@example.com", { userMeta: { first_name: "Ada" } });userMeta keys are the field names of the app's metafields. See User profile.
Results#
Every method returns { data, error }; none throws on an API error.
| data | What happened | Next |
|---|---|---|
| { magic_link: { id } } | A link was sent. magic_pending (or magic_new_device_pending) fires. | Magic links |
| { otp: { id } } | A code was sent. otp_pending (or otp_new_device_pending) fires. | One-time codes |
| null with error: null | A passkey signed the user in. signed_in fires. | Nothing |
| { mfaRequired: true, ... } | The first factor passed; a second factor is needed. | MFA |
| { contactVerificationRequired: true, ... } | The app wants an email or phone confirmed first. | Confirm a contact |
| error | Cause |
|---|---|
| IdentifierNotRecognizedError | signIn with an unknown identifier. |
| IdentifierAlreadyExistsError | signUp with a taken identifier. |
| TechnicalError | The user lookup failed. |
| BaseHttpError | The API refused (sign-up closed, rate limit, blocked IP). error.json.error holds the API's message. |
| SsoRequiredError | The email's domain must sign in with SAML. See OAuth and SSO. |
| A WebAuthn error | The passkey prompt failed. See Errors. |
Lower-level calls#
The sign-in methods are built from these, which you can call yourself:
| Method | Does |
|---|---|
| identifierExists(identifier) | Returns the user (ScuteUser) or null. Throws TechnicalError when the lookup fails. |
| sendLoginMagicLink(identifier, webauthnEnabled?, emitEvent = true) | Sends a sign-in link. |
| sendRegisterMagicLink(identifier, userMeta?, webauthnEnabled?, emitEvent = true) | Sends a sign-up link. |
| sendLoginOtp(identifier, webauthnEnabled?, emitEvent = true) | Sends a sign-in code. |
| sendRegisterOtp(identifier, userMeta?, webauthnEnabled?, emitEvent = true) | Sends a sign-up code. |
| signInWithVerifyDevice(identifier) | Signs in with a passkey on this device. |
| signInWithTokenPayload(payload) | Stores a token payload as the session and fetches the user. Emits signed_in. |
Confirm an email or phone#
An app can require a confirmed email or phone before the sign-in finishes. The sign-in then returns:
{ contactVerificationRequired: true, field: "email" | "phone", challenge: ScuteChallengeResponse | null, // a code went to the one on file setupToken: string | null, // none on file: ask for one setupExpiresAt: string | null,}contact_verification_required fires and scute.pendingContactVerification holds the step.
if (step.contactVerificationRequired) { if (!step.challenge) { // The user has no email or phone of that kind: ask for one. await scute.addSignInContact("ada@example.com"); } const { data: next, error } = await scute.verifyContactVerification(code); // next: the following step (MFA, another contact), or null when signed in}| Method | Errors |
|---|---|
| addSignInContact(identifier, setupToken?) | 400 invalid_identifier, 409 contact_taken, 401 setup_expired (sign in again), 429 setup_send_limit, 422 sms_unavailable or sms_country_not_allowed |
| verifyContactVerification(code, challengeToken?) | 422 for a wrong code, with remaining_attempts in error.json |
| resendContactVerification(challengeToken?) | Sends the code again |
The token arguments default to the pending step's.
Remembered identifier#
After each sign-in the client stores the user's email (or phone) for 400 days.
const last = await scute.getRememberedIdentifier(); // string | nullawait scute.clearRememberedIdentifier();