Installation & Setup
The SpartanAuth widgets are distributed as a single npm package that registers three custom elements (web components). They work with any modern JavaScript framework or plain HTML.
Installation
Section titled “Installation”npm install @masonitestudios/spartanauth-widgetsRegistering the widgets
Section titled “Registering the widgets”Import the package once in your application’s entry point. This registers all three custom elements globally:
import '@masonitestudios/spartanauth-widgets';After this import, <spartan-login> and <spartan-account-settings> are available as HTML elements anywhere in your app.
Getting your sector ID
Section titled “Getting your sector ID”Every widget requires a sector attribute — the UUID of this application’s app sector.
The Sector ID from signup is the tenant root. Leave that ID in the dashboard. The widget needs the app sector you create next.
- Sign in to the dashboard at
/login/{your-slug} - Open Sectors and choose New sub-sector if this app does not have one yet. See Tenant root and app sectors.
- Copy the Sector ID shown for that app sector
Store it in an environment variable so it’s easy to change per environment:
VITE_SPARTANAUTH_SECTOR=your-sector-id-hereVITE_SPARTANAUTH_DOMAIN=https://api.spartanauth.comMinimal example
Section titled “Minimal example”<spartan-login domain="https://api.spartanauth.com" sector="your-sector-id" start-mode="password" redirect="/app"></spartan-login>On successful login, the widget stores the JWT in localStorage['spartan-token'] and redirects the user to /app.
Framework integration
Section titled “Framework integration”The widgets are native web components — they work in any framework but require a small amount of wiring for event listeners and lifecycle management: