JavaScript SDK

Sign in and sign up

signInOrUp, signIn and signUp, how the client picks the method, and every result a sign-in can return.

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:

  1. 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.
  2. One-time code, when the identifier looks like a phone number or the app's email_auth_type is "otp".
  3. Magic link otherwise.

Pass { webauthn: "disabled" } to skip the passkey step.

signIn and signUp#

MethodBehavior
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.

dataWhat happenedNext
{ 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: nullA 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
errorCause
IdentifierNotRecognizedErrorsignIn with an unknown identifier.
IdentifierAlreadyExistsErrorsignUp with a taken identifier.
TechnicalErrorThe user lookup failed.
BaseHttpErrorThe API refused (sign-up closed, rate limit, blocked IP). error.json.error holds the API's message.
SsoRequiredErrorThe email's domain must sign in with SAML. See OAuth and SSO.
A WebAuthn errorThe passkey prompt failed. See Errors.

Lower-level calls#

The sign-in methods are built from these, which you can call yourself:

MethodDoes
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}
MethodErrors
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();