Skip to content
Lovelace

Auth Reference

@lovelace-ai/auth-react and @lovelace-ai/auth-nextjs are 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 varRequiredPurpose
NEXT_PUBLIC_LOVELACE_OAUTH_CLIENT_IDyesYour 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.

PropTypeDefaultPurpose
childrenReactNode—Your app tree.
initialSessionSession | null—Server-rendered session to hydrate from, avoiding a loading flash.
accountsUrlstringLovelace accounts hostOverride the accounts origin (self-hosted / non-default environments).
cookieNamestringdefault session cookieOverride the session cookie name.
signInStrategySignInStrategyplatform defaultHow the sign-in UI is presented.
fedcmFedCMAuthConfig—FedCM configuration.
enableSilentAuthboolean—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:

FieldTypeNotes
status"loading" | "authenticated" | "unauthenticated" | "error"Current session state; branch your UI on it.
signIn(returnTo?: string) => voidStart sign-in. Pass returnTo to return the user to a specific path afterward.
signOut() => Promise<void>Clear the session.

Other exports#

ExportPurpose
useAuth()Lower-level auth state (isAuthenticated(), isLoading, signInError, user info). useLovelaceSignIn is built on it.
AuthGuardComponent 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.

OptionTypeDefaultPurpose
audiencestring—Your client ID; the token audience the route validates.
sessionDurationSecondsnumberprovider defaultHow long the session cookie lasts.
requireEmailbooleantrueRequire a verified email on the identity.
sessionFactory(identity) => payloaddefault payloadCustomize what goes into the session.

Session readers#

FunctionReturnsPurpose
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.