JavaScript SDK

ScuteAuthGate and useScuteAuthFlow

Show sign-in until the visitor is authenticated, draw individual steps yourself, or run the whole flow headless.

ScuteAuthGate#

Renders its children once the visitor is signed in, and ScuteSignIn until then.

import { ScuteAuthGate } from "@scute/auth-ui-react";<ScuteAuthGate  appearance={{ logo: "/logo.svg", theme: "auto" }}  legal={{ termsUrl: "/terms", privacyUrl: "/privacy" }}  onAuthenticated={(user) => track("signed_in", user.id)}>  <App /></ScuteAuthGate>;
PropType
childrenReactNodeShown once signed in.
appearance, copy, legal, methods, defaultEmail, showLastUsedas ScuteSignInPassed to the sign-in. See Sign-in component.
onAuthenticated(user) => voidCalled once each time the app is shown after a sign-in.
renderView(view, auth) => ReactNode | nullDraw a step yourself; return null to keep the default for that step. auth is the useScuteAuthFlow() result.
<ScuteAuthGate  renderView={(view, auth) =>    view === "magic_pending" ? <p>Open the link sent to {auth.identifier}.</p> : null  }>  <App /></ScuteAuthGate>

useScuteAuthFlow#

The same flow with no UI. Render by view, call the actions.

import { useScuteAuthFlow } from "@scute/auth-ui-react";function SignIn() {  const auth = useScuteAuthFlow();  if (auth.view === "login") {    return (      <form onSubmit={(e) => { e.preventDefault(); auth.submitIdentifier(); }}>        <input value={auth.identifier} onChange={(e) => auth.setIdentifier(e.target.value)} />        <button disabled={auth.submitting}>Continue</button>        {auth.error && <p role="alert">{auth.error}</p>}      </form>    );  }  if (auth.view === "otp_input") return <CodeForm onCode={auth.submitOtp} />;  if (auth.view === "authenticated") return <p>Signed in as {auth.user?.email}</p>;  return <p>{auth.view}</p>;}

Views#

ViewShown when
loadingThe app's settings or the session are loading.
loginThe first step.
magic_pendingA link was sent; this page polls for it.
magic_verifyingA link from the address bar is being checked.
verification_requiredAttack protection wants a code.
otp_inputA code was sent.
webauthn_verifyA passkey prompt is open.
webauthn_registerThe passkey offer after a link or a code.
webauthn_register_successA passkey was added.
mfa_verifyA second factor is needed.
mfa_enrollA factor has to be set up to finish signing in.
mfa_enroll_suggestThe grace period nudge, or optional MFA whose factors the app no longer accepts.
contact_verifyAn email or phone to confirm first.
challenge_completedA step-up or custom challenge link was passed; nobody is signed in.
errorA refusal or failure. errorCode says which.
authenticatedSigned in.

State#

Field
view, identifier, error, errorCode, submittingCurrent step. errorCode is the API's code: user_banned, user_suspended, ip_blocked, country_blocked, security_block, mfa_required, or "app_settings_unavailable" (APP_SETTINGS_UNAVAILABLE) when the settings did not load.
isAuthenticated, isLoading, userThe real session, from useAuth.
identifierTypesWhat the app accepts: "email", "phone" or both.
emailSignIn"link", "code", or null until known.
passkeysSupportedThis browser can make a passkey.
lastUsedMethodHow this browser last signed in.
resendIn, resending, resent, resendErrorResend of the link or code.
finishingOnOtherDeviceThe link was opened elsewhere and that device is doing its own steps.
verificationAttack protection's challenge.
mfaChallenge, mfaAvailableMethods, mfaGracePeriod, mfaGraceDaysRemaining, mfaResent, mfaSwitchingThe MFA step.
deviceTrustOffered, deviceTrustDays, trustDevice"Trust this device" on the MFA step.
mfaSetup, mfaFactorNotAllowedA factor being set up.
contactVerificationThe email or phone to confirm.
completedChallengeThe challenge a link passed.

Actions#

ActionUse on
setIdentifier(value), submitIdentifier(identifier?)login. Without an argument it submits identifier.
signInWithOAuth(provider)login
submitOtp(code)otp_input
resend()otp_input, magic_pending, once resendIn is 0
submitVerificationCode(code)verification_required
submitMfaCode(code), resendMfaCode(), switchMfaMethod(method), setTrustDevice(on)mfa_verify
startMfaSetup(method, destination?), submitMfaSetupCode(code), restartMfaSetup()mfa_enroll, mfa_enroll_suggest
setUpMfaNow(), skipMfaEnrollment()mfa_enroll_suggest
submitContact(identifier), submitContactCode(code), resendContactCode(), changeContact()contact_verify
registerPasskey(), skipPasskey()webauthn_register
retry()error (loads the settings again after app_settings_unavailable)
signOut()authenticated