SimpleAuth
SDK

Overview

Install and configure the SimpleAuth JavaScript SDK.

The SimpleAuth SDK (@simpleauthjs/core) is a lightweight JavaScript client for the SimpleAuth auth API. It works in browsers, Node.js, edge runtimes, and any environment with a fetch implementation.

Installation

npm install @simpleauthjs/core

Building a React app? See the React integration guide.

Two entry points

ImportUse caseAPI key
@simpleauthjs/coreBrowser and client-side codePublic key (sa_live_…)
@simpleauthjs/core/serverBackend and server-side codeSecret key (sa_secret_…) or none for currentUser
// Client (browser)
import { createSimpleAuthClient } from "@simpleauthjs/core"

// Server (Node.js, Edge, etc.)
import { createServerSimpleAuthClient } from "@simpleauthjs/core/server"

Server-only import

@simpleauthjs/core/server throws an error if imported in a browser environment. This prevents accidentally shipping your secret key to clients.

Error handling

All SDK methods throw SimpleAuthError on failure. The error includes the HTTP status code, an error code, and a human-readable message.

import { SimpleAuthError } from "@simpleauthjs/core"

try {
  await auth.login({ email: "user@example.com", password: "wrong" })
} catch (error) {
  if (error instanceof SimpleAuthError) {
    console.error(error.status)  // 401
    console.error(error.code)    // "INVALID_CREDENTIALS"
    console.error(error.message) // "Invalid email or password"
  }
}

Error codes

CodeMeaning
UNAUTHORIZEDMissing or expired session.
INVALID_API_KEYThe API key is wrong or has been rotated.
INVALID_CREDENTIALSWrong email or password.
VALIDATION_ERRORA required field is missing or malformed.
USER_ALREADY_EXISTSA user with that email already exists.
RATE_LIMITEDToo many requests. Back off and retry.

Next steps

  • Client SDK — full reference for browser-side methods.
  • Server SDK — admin operations and session resolution on your backend.

On this page