Auth Reference
@lovelace-ai/auth-reactand@lovelace-ai/auth-nextjsare not yet published to npm and cannot be installed from the registry. To add Sign in with Lovelace today, use a standard OAuth 2.0 or OpenID Connect client library as shown in the quickstart.
The client surface is @lovelace-ai/auth-react (provider, hooks, guards); the
server surface is @lovelace-ai/auth-nextjs/server (the verification route and
session readers).
Configuration#
| Env var | Required | Purpose |
|---|---|---|
NEXT_PUBLIC_LOVELACE_OAUTH_CLIENT_ID | yes | Your registered OAuth app's client ID. AuthProvider reads it, and it is the audience your verification route validates against. |
assertLovelaceClientIdConfigured() — call at startup; throws if the env var is
missing, so a misconfigured build fails loudly instead of at first sign-in.
@lovelace-ai/auth-react#
AuthProvider#
Wraps your app and manages the client-side session. children is the only
required prop; the rest are optional.
| Prop | Type | Default | Purpose |
|---|---|---|---|
children | ReactNode | — | Your app tree. |
initialSession | Session | null | — | Server-rendered session to hydrate from, avoiding a loading flash. |
accountsUrl | string | Lovelace accounts host | Override the accounts origin (self-hosted / non-default environments). |
cookieName | string | default session cookie | Override the session cookie name. |
signInStrategy | SignInStrategy | platform default | How the sign-in UI is presented. |
fedcm | FedCMAuthConfig | — | FedCM configuration. |
enableSilentAuth | boolean | — | Attempt silent re-authentication. |
onSignInSuccess | (identity) => void | — | Called after a successful sign-in. |
onSignInError | (error) => void | — | Called on sign-in failure. |
onSignOut | () => void | — | Called after sign-out. |
useLovelaceSignIn()#
The high-level sign-in hook. Returns LovelaceSignInHookResult:
| Field | Type | Notes |
|---|---|---|
status | "loading" | "authenticated" | "unauthenticated" | "error" | Current session state; branch your UI on it. |
signIn | (returnTo?: string) => void | Start sign-in. Pass returnTo to return the user to a specific path afterward. |
signOut | () => Promise<void> | Clear the session. |
Other exports#
| Export | Purpose |
|---|---|
useAuth() | Lower-level auth state (isAuthenticated(), isLoading, signInError, user info). useLovelaceSignIn is built on it. |
AuthGuard | Component wrapper that renders children only when authenticated. |
withAuth(Component, options) | HOC equivalent of AuthGuard. |
useWebAuthn() | Passkey/WebAuthn registration and authentication. |
@lovelace-ai/auth-nextjs/server#
createLovelaceSignInRoute(options)#
Returns a Next.js route handler (export it as POST) that verifies the sign-in
result the SDK posts back and sets a secure session cookie.
| Option | Type | Default | Purpose |
|---|---|---|---|
audience | string | — | Your client ID; the token audience the route validates. |
sessionDurationSeconds | number | provider default | How long the session cookie lasts. |
requireEmail | boolean | true | Require a verified email on the identity. |
sessionFactory | (identity) => payload | default payload | Customize what goes into the session. |
Session readers#
| Function | Returns | Purpose |
|---|---|---|
getSession() | Promise<SessionData | null> | The current server-side session, or null if not signed in. Use in Server Components and route handlers to gate and personalize. |
getAccessToken() | Promise<string | null> | The signed-in user's access token, to call Lovelace APIs (e.g. Lattice Cloud) as that user. |
Errors#
The SDK surfaces typed sign-in errors on useAuth().signInError and via
onSignInError. On the server, a request whose grant was revoked or is missing a
scope fails with a typed error (revoked_grant, insufficient_scopes) — re-run
the sign-in flow rather than retrying blindly. See
Troubleshooting.
Related#
- Quickstart — a complete runnable integration
- External integration
- Production hardening