Quick Start
import { Steps } from ‘@astrojs/starlight/components’;
This guide walks through the minimal integration. By the end, your users will be able to log in through a SpartanAuth-powered widget and your backend will be able to verify their identity.
-
Create a sector in the dashboard
Log in to the SpartanAuth dashboard and create a new sector for your application. Give it a name and set your application’s domain as the allowed origin.
Copy your Sector ID — you’ll need it in the next step.
-
Add the login widget to your frontend
Install the widgets package:
Terminal window npm install @masonitestudios/spartanauth-widgetsImport it once in your app’s entry point:
import '@masonitestudios/spartanauth-widgets';Add the login widget wherever you want the login form:
<spartan-logindomain="https://api.spartanauth.com"sector="YOUR_SECTOR_ID"start-mode="password"redirect="/app"></spartan-login>Replace
YOUR_SECTOR_IDwith the ID you copied from the dashboard. When a user logs in successfully, they’ll be redirected to/appand a JWT will be stored inlocalStorage['spartan-token']. -
Verify tokens in your backend
When your frontend makes an API call, it sends the JWT in the
Authorizationheader:Authorization: Bearer <token>Your backend verifies it by calling the introspection endpoint:
Terminal window curl -X POST https://api.spartanauth.com/api/v1/introspect \-H "Content-Type: application/json" \-d '{"token": "<jwt>"}'A valid token returns HTTP 200 with the user’s identity:
{"sub": "3f2a8c1d-...","sectorID": "a1b2c3d4-...","isAdmin": false,"exp": "1717000000","iat": "1716996400"}An invalid or expired token returns HTTP 401. See the Go backend example for a production-ready implementation.
What’s next?
Section titled “What’s next?”- Frontend framework: See the Vue 3, React, or Vanilla JS integration guides.
- All widget options: Check the Widgets Reference for the full attribute and event API.
- Protecting routes with Traefik: See Traefik ForwardAuth.
- Let users manage their account: Add the
<spartan-account-settings>widget to your app.