StackClientApp class provides client-side authentication capabilities for JavaScript applications.
Constructor
Constructor Options
Your Stack Auth project ID. Defaults to environment variable based on your framework:
- Vite:
VITE_STACK_PROJECT_ID - Create React App:
REACT_APP_STACK_PROJECT_ID - Next.js:
NEXT_PUBLIC_STACK_PROJECT_ID
Your publishable client key. Defaults to environment variable:
- Vite:
VITE_STACK_PUBLISHABLE_CLIENT_KEY - Create React App:
REACT_APP_STACK_PUBLISHABLE_CLIENT_KEY - Next.js:
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY
Token storage mechanism:
'cookie'- HTTP cookies (recommended)'localStorage'- Browser local storage'sessionStorage'- Browser session storage'memory'- Memory only (lost on refresh)
Stack Auth API base URL. Defaults to
https://api.stack-auth.com.Can be a string or an object:Custom URL configuration for authentication pages.
OAuth scopes to request during sign in.
Navigation method for redirects:
'redirect'- Full page redirect (default)'push'- Client-side navigation (adds to history)'replace'- Client-side navigation (replaces history)
Disable automatic data prefetching. By default, Stack Auth prefetches user data when the app is created. Set to
true to disable this behavior.Additional headers to include in all API requests.
Properties
projectId
The configured project ID:version
The SDK version:urls
Configured authentication URLs:Token Storage
Cookie Storage (Recommended)
- Secure (HttpOnly, SameSite)
- Works across tabs
- Persists across sessions
- Requires proper CORS configuration
- Size limitations
Local Storage
- Large storage capacity
- Works across tabs
- Persists across sessions
- Vulnerable to XSS attacks
- Not secure by default
Session Storage
- Cleared when tab is closed
- Isolated per tab
- Lost on tab close
- Not shared across tabs
- Vulnerable to XSS attacks
Memory Storage
- Most secure (not persisted)
- No storage limitations
- Lost on page refresh
- Not shared across tabs
- Poor user experience
URL Configuration Examples
Custom Authentication Pages
External Authentication Server
OAuth Scopes
Request additional OAuth scopes:Custom Base URL
Use a custom API endpoint:Multiple Instances
Create multiple Stack app instances for different projects:Best Practices
Use cookie storage
Cookie storage is the most secure option for web applications.
Set environment variables
Store credentials in environment variables, not in source code.
Configure custom URLs
Customize authentication URLs to match your app’s routing structure.
Request minimal scopes
Only request OAuth scopes that your application actually needs.