Widgets Reference
The @masonitestudios/spartanauth-widgets package ships two web components. Both render inside Shadow DOM, which means their internal styles are isolated from your application’s CSS.
<spartan-login>
Section titled “<spartan-login>”The full-featured login form. Handles password login, passkey (WebAuthn) login, email-code challenges, authenticator-app (TOTP) challenges, self-service sign-up, and password reset — all within a single widget. SMS codes are not offered.
<spartan-login domain="https://api.spartanauth.com" sector="your-sector-id" start-mode="password" locale="en" redirect="" styles=""></spartan-login>Attributes
Section titled “Attributes”| Attribute | Default | Description |
|---|---|---|
domain | https://api.spartanauth.com | SpartanAuth API base URL |
sector | (required) | Sector ID of this app sector. In the dashboard, choose New sub-sector and copy that ID. Do not use the tenant root ID from signup. See Tenant root and app sectors. |
start-mode | password | Initial login mode: password or webauthn |
locale | en | UI language: en, fr, es, ja |
redirect | "" | URL to navigate to after a successful login. Leave empty to suppress automatic navigation and handle the spartan-login event yourself. |
styles | "" | CSS string injected into the widget’s shadow DOM for custom styling |
Events
Section titled “Events”spartan-login — fired on the element after a successful login.
element.addEventListener('spartan-login', (event: CustomEvent) => { const { token, transactionID } = event.detail; // token is also stored in localStorage['spartan-token']});Features
Section titled “Features”- Password and WebAuthn (passkey) login
- Email-code challenge, with a method picker when more than one method is enrolled
- Authenticator-app codes and one-time recovery codes
- Self-service sign-up (when enabled on the app sector)
- Password reset via emailed code
- A paused sign-in when the sector requires a reset of a known breached password. See Breached passwords.
When the sector requires MFA, a successful password check returns challengeType as comma-separated whole tokens. Match the whole token. totp contains the letters otp, and it is a different method.
| Token | Widget behavior |
|---|---|
otp | Ask for the email code. |
totp | Ask for a 6-digit authenticator code. A recovery-code field sends the same login request with the recovery code in code. |
webauthn | Offer a passkey. |
email_enrollment | Offer to enroll an email code. |
totp_enrollment | Offer to enroll an authenticator app. |
pwned_password | The password is correct and already known to be breached, and the sector requires a reset before password sign-in can finish. No token is returned. The widget explains that sign-in is paused and emails a reset code. It does not continue to another factor. |
The username stays locked on that screen so the reset email goes to the account that just signed in. Back returns to the sign-in form without storing a session. After the code is accepted, the user chooses a new password. A breached replacement stays on that screen with the server’s message, and the code is not treated as invalid. Passkey and email-code sign-in do not produce this challenge.
An embedded widget that does not recognize pwned_password stops on the response without the reset screen. Update @masonitestudios/spartanauth-widgets before turning Require reset of breached passwords on. The full administrator and end-user flow is in Breached passwords.
If totp is the only second factor, the widget opens the code screen directly. The login request is POST /api/v1/login/totp with username, code, transactionID, and sectorID. An invalid code stays on that screen.
totp_enrollment uses the password-proven transaction already in the flow, including the sign-up transaction. The widget draws the QR code in the browser from otpauthURL and shows the secret so the user can type it. The first enrollment returns eight recovery codes. The widget stores the token and fires spartan-login only after the user confirms those codes were saved. A second authenticator returns an empty recoveryCodes list. Canceling enrollment drops the secret from the page.
<spartan-account-settings>
Section titled “<spartan-account-settings>”An authenticated self-service settings panel. Lets logged-in users change their password, manage passkeys, email codes, and authenticator apps, and see a warning when the current password has appeared in a data breach.
<spartan-account-settings domain="https://api.spartanauth.com" sector="your-sector-id" locale="en" redirect="/" show-web-authn="true" show-totp="true" show-skeleton="true" redirect-on-unauthenticated="true"></spartan-account-settings>Attributes
Section titled “Attributes”| Attribute | Default | Description |
|---|---|---|
domain | https://api.spartanauth.com | SpartanAuth API base URL |
sector | (required) | Same as <spartan-login> — this app sector’s ID. On a profile page, use the sectorID claim from the signed-in token, not a sector an administrator is browsing. |
locale | en | UI language |
redirect | / | Redirect target when the user is not authenticated |
show-web-authn | true | Show the passkey management section |
show-totp | true | Show the authenticator-app section |
show-skeleton | false | Show a placeholder until the account MFA choice, passkeys, email codes, and authenticator apps have loaded, then paint those sections once |
redirect-on-unauthenticated | true | Automatically redirect unauthenticated users |
styles | "" | Custom CSS injected into the shadow DOM |
Features
Section titled “Features”- Change the signed-in password. When that password is breached, the panel warns the user, shows the breach count when one is known, and can email a reset code. The warning is based on the stored check, including when the sector has not required a reset at sign-in. A breached replacement is refused, and a check that cannot reach the breach list leaves the current password in place.
- Require a second factor for this account. The checkbox sits under the password section and applies to every method below it: passkeys, email codes, and authenticator apps. It is omitted when the platform or the sector already requires MFA, and it cannot turn those requirements off. The next password, email-code, or authenticator sign-in asks for a second factor. Existing sessions stay valid. Passkey and social sign-in are unchanged.
- List, add, and remove WebAuthn passkeys
- List, add, validate, and remove email-code registrations. The phone number field is hidden until SMS sending is available. An existing phone registration can still be removed.
- List, add, and remove authenticator apps. The list shows the display name, not the shared secret
- Optional skeleton while the first settings load is in flight (
show-skeleton="true") - MFA verification modal with one-time code input
- Reads the JWT from
localStorage['spartan-token']for authenticated API calls
The authenticator section is titled “Authenticator app”. Adding one uses the signed-in token. The recovery-code dialog appears only when enrollment returns codes, which is the first authenticator for that user. Removing the last authenticator while the platform or sector requires MFA is refused for a non-admin. The widget explains that an administrator must turn that requirement off. When only the user’s own opt-in requires MFA, the user turns that off in account settings first, including an administrator. A passkey or a validated email or text code still counts as another method, so the authenticator can be removed while one of those remains.