Skip to main content
npm install @insforge/sdk@latest
import { createClient } from '@insforge/sdk';

const insforge = createClient({
  baseUrl: 'https://your-app.us-east.insforge.app',
  anonKey: 'your-anon-key'  // Optional: for public/unauthenticated requests
});

signUp()

Create a new user account with email and password.

Parameters

  • email (string, required) - User’s email address
  • password (string, required) - User’s password
  • name (string, optional) - User’s display name

Returns

{
  data: {
    user: { id, email, name, emailVerified, createdAt, updatedAt },
    accessToken: string
  } | null,
  error: Error | null
}

Example

const { data, error } = await insforge.auth.signUp({
  email: '[email protected]',
  password: 'secure_password123',
  name: 'John Doe'
})

Output

{
  "data": {
    "user": {
      "id": "usr_abc123",
      "email": "[email protected]",
      "name": "John Doe",
      "emailVerified": false,
      "createdAt": "2024-01-15T10:00:00Z",
      "updatedAt": "2024-01-15T10:00:00Z"
    },
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  },
  "error": null
}

signInWithPassword()

Sign in an existing user with email and password.

Parameters

  • email (string, required) - User’s email address
  • password (string, required) - User’s password

Returns

{
  data: {
    user: { id, email, name, emailVerified, createdAt, updatedAt },
    accessToken: string
  } | null,
  error: Error | null
}

Example

const { data, error } = await insforge.auth.signInWithPassword({
  email: '[email protected]',
  password: 'secure_password123'
})

Output

{
  "data": {
    "user": {
      "id": "usr_abc123",
      "email": "[email protected]",
      "name": "John Doe",
      "emailVerified": true,
      "createdAt": "2024-01-15T10:00:00Z",
      "updatedAt": "2024-01-15T10:00:00Z"
    },
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  },
  "error": null
}

signInWithOAuth()

Start OAuth authentication flow with supported providers (Google, GitHub, Microsoft, Discord, and more).

Parameters

  • provider (string, required) - OAuth provider name (e.g., ‘google’, ‘github’, ‘microsoft’, ‘discord’)
  • redirectTo (string, optional) - URL to redirect after authentication
  • skipBrowserRedirect (boolean, optional) - If true, returns OAuth URL without auto-redirecting (for mobile apps)

Returns

{
  data: { url?: string, provider?: string },
  error: Error | null
}
After OAuth redirect, SDK automatically detects callback parameters and saves session. No manual handling needed.

Example

// Default: auto-redirect
await insforge.auth.signInWithOAuth({
  provider: 'google',
  redirectTo: 'http://localhost:3000/dashboard'
})
// Browser immediately redirects to Google

// skipBrowserRedirect: get URL for manual handling
const { data } = await insforge.auth.signInWithOAuth({
  provider: 'google',
  skipBrowserRedirect: true
})

window.location.href = data.url // Redirect when ready

Output

{
  "data": {
    "url": "https://accounts.google.com/o/oauth2/v2/auth?client_id=...",
    "provider": "google"
  },
  "error": null
}

signOut()

Sign out the current user and clear session.

Parameters

None

Returns

{
  error: Error | null
}

Example

const { error } = await insforge.auth.signOut()

Output

{
  "error": null
}

getCurrentUser()

Get authenticated user with profile data from users table.

Parameters

None

Returns

{
  data: {
    user: { id, email, role },
    profile: { id, nickname, avatar_url, bio, birthday, ... }
  } | null,
  error: Error | null
}

Example

const { data, error } = await insforge.auth.getCurrentUser()

if (data) {
  console.log(data.user.email)        // Auth info
  console.log(data.profile.nickname)  // Profile from users table
}

Output

{
  "data": {
    "user": {
      "id": "usr_abc123",
      "email": "[email protected]",
      "role": "authenticated"
    },
    "profile": {
      "id": "usr_abc123",
      "nickname": "JohnDoe",
      "avatar_url": "https://example.com/avatar.jpg",
      "bio": "Full-stack developer",
      "birthday": "1990-01-01"
    }
  },
  "error": null
}

getCurrentSession()

Get current session from local storage (no API call).

Parameters

None

Returns

{
  data: {
    session: {
      accessToken: string,
      user: { id, email, name, ... }
    } | null
  },
  error: Error | null
}

Example

const { data, error } = await insforge.auth.getCurrentSession()

if (data.session) {
  console.log('Token:', data.session.accessToken)
}

Output

{
  "data": {
    "session": {
      "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "user": {
        "id": "usr_abc123",
        "email": "[email protected]",
        "name": "John Doe"
      }
    }
  },
  "error": null
}

getProfile()

Get any user’s public profile by ID.

Parameters

  • userId (string, required) - User ID to fetch profile for

Returns

{
  data: { id, nickname, avatar_url, bio, birthday, ... } | null,
  error: Error | null
}

Example

const { data: profile, error } = await insforge.auth.getProfile('usr_xyz789')

console.log(profile.nickname)

Output

{
  "data": {
    "id": "usr_xyz789",
    "nickname": "JaneDoe",
    "avatar_url": "https://example.com/jane.jpg",
    "bio": "Designer and developer",
    "birthday": "1992-05-15"
  },
  "error": null
}

setProfile()

Update current user’s profile in users table.

Parameters

  • nickname (string, optional) - User’s display name
  • avatar_url (string, optional) - Profile picture URL
  • bio (string, optional) - User biography
  • birthday (string, optional) - Birth date (YYYY-MM-DD format)

Returns

{
  data: { id, nickname, avatar_url, bio, birthday, ... } | null,
  error: Error | null
}

Example

const { data: profile, error } = await insforge.auth.setProfile({
  nickname: 'JohnDev',
  bio: 'Full-stack developer',
  avatar_url: 'https://example.com/avatar.jpg'
})

Output

{
  "data": {
    "id": "usr_abc123",
    "nickname": "JohnDev",
    "avatar_url": "https://example.com/avatar.jpg",
    "bio": "Full-stack developer",
    "birthday": null
  },
  "error": null
}

Error Handling

All auth methods return structured errors:
const { data, error } = await insforge.auth.signInWithPassword({
  email: '[email protected]',
  password: 'wrong_password'
})

if (error) {
  console.error(error.statusCode)    // 401
  console.error(error.error)         // 'INVALID_CREDENTIALS'
  console.error(error.message)       // 'Invalid login credentials'
  console.error(error.nextActions)   // 'Check email and password'
}