Skip to main content
The Gately SDK provides a simple, type-safe way to integrate authentication, user management, and content protection into your applications.

Features

Authentication

Email/password, social login, and magic links

User Management

Profiles, sessions, and account management

Page Protection

Protect content based on authentication and plans

Forms

Embed and submit forms programmatically

Authentication Methods

The SDK supports two authentication methods depending on your environment:
EnvironmentMethodKey Type
Browser/ClientProject IDPublic (safe to expose)
Server/Node.jsAPI KeySecret (never expose)
Never expose API keys in client-side code. Use Project IDs for browser applications and API keys only on the server.

Quick Start

Installation

npm install gately

Browser Usage

For client-side applications, initialize with your API key:
import { GatelyClient } from 'gately'

// Initialize with API key
const gately = new GatelyClient({
  apiKey: 'gately_pk_live_xxxxxxxx'
})

// Check if user is authenticated
if (gately.isAuthenticated()) {
  const user = gately.getUser()
  console.log('Welcome,', user.email)
}

// Login
const { user, session } = await gately.login('[email protected]', 'password')

// Logout
await gately.logout()

React Usage

import { GatelyProvider, useGately } from 'gately'

// Wrap your app with the provider
function App() {
  return (
    <GatelyProvider apiKey="gately_pk_live_xxxxxxxx">
      <YourApp />
    </GatelyProvider>
  )
}

// Use in components
function Profile() {
  const { user, isAuthenticated, login, logout } = useGately()
  
  if (!isAuthenticated) {
    return <button onClick={() => login('[email protected]', 'pass')}>Login</button>
  }
  
  return (
    <div>
      <p>Welcome, {user.email}</p>
      <button onClick={logout}>Logout</button>
    </div>
  )
}

Server-Side Usage (Node.js)

For server-side applications, use your secret API key:
import { GatelyNodeClient } from 'gately/node'

// Initialize with secret API key
const gately = new GatelyNodeClient({
  apiKey: process.env.GATELY_API_KEY // gately_sk_live_xxxxxxxx
})

// Verify user tokens
const user = await gately.verifyToken(token)

// List members
const members = await gately.listMembers()

// Create a member
const member = await gately.createMember({
  email: '[email protected]',
  full_name: 'John Doe'
})

API Key Types

Key TypePrefixUsageSecurity
Public Keygately_pk_Browser/client appsSafe to expose
Secret Keygately_sk_Server-side onlyNever expose
Get your API keys from Settings → API Keys in your Gately dashboard.

SDK Methods

Authentication

MethodDescription
login(email, password)Login with email and password
signup(email, password, metadata)Create a new account
loginWithGoogle(options)Login with Google OAuth
loginWithGithub(options)Login with GitHub OAuth
sendMagicLink(email, options)Send a passwordless login link
logout()End the current session

Session Management

MethodDescription
isAuthenticated()Check if user is logged in
getUser()Get the current user
getSession()Get the current session
fetchSession()Refresh and fetch session from server
onAuthStateChange(callback)Listen for auth state changes

User Profile

MethodDescription
getUserProfile()Get detailed user profile
updateUserProfile(updates)Update user profile
changePassword(current, new)Change user password
deleteUserAccount()Delete the user’s account

Page Protection

MethodDescription
initPageProtection(options)Initialize automatic page protection
checkAccess(contentId)Check if user can access content

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:
import { 
  GatelyClient, 
  User, 
  Session, 
  AuthResponse 
} from '@gately/sdk'

const gately = new GatelyClient({
  apiKey: 'gately_pk_live_xxxxxxxx'
})

const handleLogin = async (): Promise<AuthResponse> => {
  return await gately.login('[email protected]', 'password')
}

Configuration Options

const gately = new GatelyClient({
  // Required: Your API key
  apiKey: 'gately_pk_live_xxxxxxxx',
  
  // Optional: Custom API URL (for self-hosted)
  apiUrl: 'https://api.usegately.com',
  
  // Optional: Auto-refresh sessions before expiry
  autoRefresh: true,
  
  // Optional: Suppress console errors
  suppressConsoleErrors: false
})

Next Steps