Configure Auth
const client = new Jupiter( 'https://api.jupitercloud.co', 'project-id', 'optional-team-api-key', { auth: { 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 client = new Jupiter( 'https://api.jupitercloud.co', 'project-id', 'optional-team-api-key', { auth: { throwOnError: true } }) try { const { data } = await client.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 client = new Jupiter( 'https://api.jupitercloud.co', 'project-id', 'optional-team-api-key', { auth: { skipAutoInitialize: true } }) const result = await client.auth.initialize() if (result.error) { throw result.error}