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>;| Prop | Type | |
|---|---|---|
| children | ReactNode | Shown once signed in. |
| appearance, copy, legal, methods, defaultEmail, showLastUsed | as ScuteSignIn | Passed to the sign-in. See Sign-in component. |
| onAuthenticated | (user) => void | Called once each time the app is shown after a sign-in. |
| renderView | (view, auth) => ReactNode | null | Draw 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#
| View | Shown when |
|---|---|
| loading | The app's settings or the session are loading. |
| login | The first step. |
| magic_pending | A link was sent; this page polls for it. |
| magic_verifying | A link from the address bar is being checked. |
| verification_required | Attack protection wants a code. |
| otp_input | A code was sent. |
| webauthn_verify | A passkey prompt is open. |
| webauthn_register | The passkey offer after a link or a code. |
| webauthn_register_success | A passkey was added. |
| mfa_verify | A second factor is needed. |
| mfa_enroll | A factor has to be set up to finish signing in. |
| mfa_enroll_suggest | The grace period nudge, or optional MFA whose factors the app no longer accepts. |
| contact_verify | An email or phone to confirm first. |
| challenge_completed | A step-up or custom challenge link was passed; nobody is signed in. |
| error | A refusal or failure. errorCode says which. |
| authenticated | Signed in. |
State#
| Field | |
|---|---|
| view, identifier, error, errorCode, submitting | Current 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, user | The real session, from useAuth. |
| identifierTypes | What the app accepts: "email", "phone" or both. |
| emailSignIn | "link", "code", or null until known. |
| passkeysSupported | This browser can make a passkey. |
| lastUsedMethod | How this browser last signed in. |
| resendIn, resending, resent, resendError | Resend of the link or code. |
| finishingOnOtherDevice | The link was opened elsewhere and that device is doing its own steps. |
| verification | Attack protection's challenge. |
| mfaChallenge, mfaAvailableMethods, mfaGracePeriod, mfaGraceDaysRemaining, mfaResent, mfaSwitching | The MFA step. |
| deviceTrustOffered, deviceTrustDays, trustDevice | "Trust this device" on the MFA step. |
| mfaSetup, mfaFactorNotAllowed | A factor being set up. |
| contactVerification | The email or phone to confirm. |
| completedChallenge | The challenge a link passed. |
Actions#
| Action | Use 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 |