Configure Auth
import { JupiterAuth } from '@jupiter-cloud/auth' const auth = new JupiterAuth('https://api.jupitercloud.co/auth', { projectId: 'project-id', storageKey: 'my-app.auth', autoRefreshToken: true, persistSession: true, detectSessionInUrl: true, flowType: 'pkce', throwOnError: false, debug: false})Session storage
- persistSession defaults to true. Browser clients use localStorage when no custom storage is supplied.
- When persistence is disabled, the session remains in memory.
- storage can provide synchronous or asynchronous getItem, setItem, and removeItem methods.
- userStorage stores the user separately from token data and is experimental.
OAuth callback detection
detectSessionInUrl can be a boolean or a function. Use a function when another OAuth integration also returns access-token parameters to the same application.
auth: { detectSessionInUrl: (url, params) => { if (url.pathname === '/other-provider/callback') { return false } return Boolean( params.access_token || params.error_description || params.code ) }}Thrown errors
By default, Auth resolves requests with an error field. Enable throwOnError to reject the promise when a request returns an Auth error.
const auth = new JupiterAuth('https://api.jupitercloud.co/auth', { projectId: 'project-id', throwOnError: true}) try { const { data } = await auth.signInWithEmailAndPassword({ email, password })} catch (error) { console.error(error)}Initialize manually
The Auth client initializes automatically by default. When skipAutoInitialize is enabled, call initialize before using Auth methods.
const auth = new JupiterAuth('https://api.jupitercloud.co/auth', { projectId: 'project-id', skipAutoInitialize: true}) const result = await auth.initialize() if (result.error) { throw result.error}