Skip to content

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.

Terminal window
npm install @masonitestudios/spartanauth-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.

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.

  1. Sign in to the dashboard at /login/{your-slug}
  2. Open Sectors and choose New sub-sector if this app does not have one yet. See Tenant root and app sectors.
  3. Copy the Sector ID shown for that app sector

Store it in an environment variable so it’s easy to change per environment:

.env
VITE_SPARTANAUTH_SECTOR=your-sector-id-here
VITE_SPARTANAUTH_DOMAIN=https://api.spartanauth.com
<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.

The widgets are native web components — they work in any framework but require a small amount of wiring for event listeners and lifecycle management: