Documentation Index
Fetch the complete documentation index at: https://usegately.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Gately supports OAuth authentication with Google and GitHub, allowing users to sign in with their existing accounts.
Google Login
await gately.loginWithGoogle(options)
Options
| Option | Type | Default | Description |
|---|
redirectTo | string | Current URL | URL to redirect after login |
Example
// Simple usage
await gately.loginWithGoogle()
// With redirect
await gately.loginWithGoogle({
redirectTo: '/dashboard'
})
React Component
function GoogleLoginButton() {
const { loginWithGoogle } = useGately()
return (
<button onClick={() => loginWithGoogle({ redirectTo: '/dashboard' })}>
<GoogleIcon />
Continue with Google
</button>
)
}
GitHub Login
await gately.loginWithGithub(options)
Options
| Option | Type | Default | Description |
|---|
redirectTo | string | Current URL | URL to redirect after login |
Example
// Simple usage
await gately.loginWithGithub()
// With redirect
await gately.loginWithGithub({
redirectTo: '/dashboard'
})
React Component
function GithubLoginButton() {
const { loginWithGithub } = useGately()
return (
<button onClick={() => loginWithGithub({ redirectTo: '/dashboard' })}>
<GithubIcon />
Continue with GitHub
</button>
)
}
OAuth Flow
- User clicks social login button
- SDK redirects to OAuth provider (Google/GitHub)
- User authorizes your application
- Provider redirects back with auth code
- SDK exchanges code for session
- User is logged in and redirected
Configuration
Enable OAuth Providers
- Go to Settings > Authentication in your dashboard
- Enable Google and/or GitHub
- Add your OAuth credentials
Google Setup
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
https://api.usegately.com/api/v1/sso/google/callback
- Copy Client ID and Client Secret to Gately
GitHub Setup
- Go to GitHub Developer Settings
- Create a new OAuth App
- Set Authorization callback URL:
https://api.usegately.com/api/v1/sso/github/callback
- Copy Client ID and Client Secret to Gately
Custom Domain
If you have a custom domain configured:
// SDK automatically uses your custom domain for OAuth
await gately.loginWithGoogle()
// Redirects to: https://auth.yourdomain.com/api/sso/google
Handling OAuth Redirect
The SDK automatically handles OAuth redirects. After successful authentication:
- Session is saved to localStorage
- Cookies are set for cross-origin requests
gately:auth-success event is dispatched
- User is redirected to
redirectTo URL
// Listen for OAuth success
window.addEventListener('gately:auth-success', (event) => {
const { session, user } = event.detail
console.log('OAuth login successful:', user.email)
})
// Listen for OAuth errors
window.addEventListener('gately:auth-error', (event) => {
const { error, message } = event.detail
console.error('OAuth failed:', message)
})
Error Handling
try {
await gately.loginWithGoogle()
} catch (error) {
// Note: Most errors occur during redirect, not here
console.error('Failed to initiate OAuth:', error)
}
// Handle errors from redirect
window.addEventListener('gately:auth-error', (event) => {
const { error, message } = event.detail
switch (error) {
case 'access_denied':
showError('You cancelled the login')
break
case 'invalid_request':
showError('Login configuration error')
break
default:
showError('Login failed. Please try again.')
}
})
User Data from OAuth
OAuth providers return user profile data:
Google
{
email: 'user@gmail.com',
full_name: 'John Doe',
avatar_url: 'https://lh3.googleusercontent.com/...',
metadata: {
google_id: '123456789',
locale: 'en'
}
}
GitHub
{
email: 'user@example.com',
full_name: 'johndoe',
avatar_url: 'https://avatars.githubusercontent.com/...',
metadata: {
github_id: 12345,
github_username: 'johndoe'
}
}
Linking Accounts
If a user signs up with email and later tries to login with OAuth using the same email, the accounts are automatically linked.
// User signs up with email
await gately.signup('user@example.com', 'password')
// Later, user logs in with Google (same email)
await gately.loginWithGoogle()
// Same account, now linked to Google