superapp
ReferenceHTTP API

Auth Endpoints

Authentication API routes.

The auth endpoints handle user authentication, session management, and account recovery. They are served under the /auth path when an auth provider is configured.

All auth endpoints accept and return JSON. No JWT is required for authentication endpoints (they are how you obtain one).

Endpoints Overview

MethodPathDescription
POST/auth/sign-inAuthenticate with email and password
POST/auth/sign-upCreate a new user account
POST/auth/sign-outInvalidate the current session
GET/auth/sessionGet the current session and user info
POST/auth/forgot-passwordRequest a password reset email
POST/auth/reset-passwordReset password with a token
POST/auth/verify-emailVerify an email address with a token

POST /auth/sign-in

Authenticate a user with email and password. Returns a session token (JWT) on success.

Request

{
  "email": "alice@example.com",
  "password": "s3cure-passw0rd"
}
FieldTypeRequiredDescription
emailstringYesThe user's email address.
passwordstringYesThe user's password.

Response (200 OK)

{
  "user": {
    "id": "usr_42",
    "email": "alice@example.com",
    "name": "Alice",
    "emailVerified": true,
    "createdAt": "2025-01-15T10:00:00Z"
  },
  "session": {
    "token": "eyJhbGciOiJSUzI1NiIs...",
    "expiresAt": "2025-03-23T10:00:00Z"
  }
}

Errors

StatusError CodeCondition
401INVALID_CREDENTIALSEmail or password is incorrect.
403EMAIL_NOT_VERIFIEDEmail verification is required but not completed (when emailVerification: true).
429RATE_LIMITEDToo many sign-in attempts.

POST /auth/sign-up

Create a new user account. Returns the created user and a session token.

Request

{
  "email": "bob@example.com",
  "password": "s3cure-passw0rd",
  "name": "Bob"
}
FieldTypeRequiredDescription
emailstringYesEmail address for the new account. Must be unique.
passwordstringYesPassword. Minimum 8 characters.
namestringNoDisplay name for the user.

Response (201 Created)

{
  "user": {
    "id": "usr_43",
    "email": "bob@example.com",
    "name": "Bob",
    "emailVerified": false,
    "createdAt": "2025-03-16T12:00:00Z"
  },
  "session": {
    "token": "eyJhbGciOiJSUzI1NiIs...",
    "expiresAt": "2025-03-23T12:00:00Z"
  }
}

When emailVerification is enabled, the session token is still returned but data access may be restricted until the email is verified.

Errors

StatusError CodeCondition
400VALIDATION_ERRORMissing required fields or password too short.
409EMAIL_EXISTSAn account with this email already exists.
429RATE_LIMITEDToo many sign-up attempts.

POST /auth/sign-out

Invalidate the current session. Requires an active JWT.

Request

POST /auth/sign-out HTTP/1.1
Authorization: Bearer <jwt_token>

No request body is needed.

Response (200 OK)

{
  "success": true
}

After sign-out, the JWT is invalidated server-side. Subsequent requests using the same token receive 401 Unauthorized.

Errors

StatusError CodeCondition
401UNAUTHORIZEDNo valid session token provided.

GET /auth/session

Retrieve the current session and user information. Requires an active JWT.

Request

GET /auth/session HTTP/1.1
Authorization: Bearer <jwt_token>

Response (200 OK)

{
  "user": {
    "id": "usr_42",
    "email": "alice@example.com",
    "name": "Alice",
    "emailVerified": true,
    "createdAt": "2025-01-15T10:00:00Z"
  },
  "session": {
    "token": "eyJhbGciOiJSUzI1NiIs...",
    "expiresAt": "2025-03-23T10:00:00Z"
  }
}

If the session is within the refreshWindow, the response includes a refreshed token with an extended expiration.

Errors

StatusError CodeCondition
401UNAUTHORIZEDToken is missing, invalid, or expired.

POST /auth/forgot-password

Request a password reset. Sends an email with a reset token. Always returns 200 OK regardless of whether the email exists (to prevent email enumeration).

Request

{
  "email": "alice@example.com"
}
FieldTypeRequiredDescription
emailstringYesEmail address of the account to reset.

Response (200 OK)

{
  "success": true,
  "message": "If an account with that email exists, a reset link has been sent."
}

Errors

StatusError CodeCondition
429RATE_LIMITEDToo many reset requests.

POST /auth/reset-password

Reset a password using the token received via email.

Request

{
  "token": "rst_abc123def456",
  "password": "new-s3cure-passw0rd"
}
FieldTypeRequiredDescription
tokenstringYesThe reset token from the email link.
passwordstringYesThe new password. Minimum 8 characters.

Response (200 OK)

{
  "success": true,
  "message": "Password has been reset. Please sign in with your new password."
}

Errors

StatusError CodeCondition
400INVALID_TOKENThe reset token is invalid or expired.
400VALIDATION_ERRORNew password does not meet requirements.

POST /auth/verify-email

Verify an email address using the token sent during sign-up.

Request

{
  "token": "vrf_abc123def456"
}
FieldTypeRequiredDescription
tokenstringYesThe verification token from the email link.

Response (200 OK)

{
  "success": true,
  "message": "Email verified successfully."
}

Errors

StatusError CodeCondition
400INVALID_TOKENThe verification token is invalid or expired.

Client SDK Usage

The @superapp/auth client SDK wraps these endpoints for convenience:

import { createAuth } from '@superapp/auth'

const auth = createAuth('http://localhost:3001')

// Sign up
const { user, session } = await auth.signUp({
  email: 'bob@example.com',
  password: 's3cure-passw0rd',
  name: 'Bob',
})

// Sign in
const { user, session } = await auth.signIn({
  email: 'alice@example.com',
  password: 's3cure-passw0rd',
})

// Get current session
const { user, session } = await auth.getSession()

// Sign out
await auth.signOut()

// Forgot password
await auth.forgotPassword({ email: 'alice@example.com' })

// Reset password
await auth.resetPassword({
  token: 'rst_abc123def456',
  password: 'new-s3cure-passw0rd',
})

// Verify email
await auth.verifyEmail({ token: 'vrf_abc123def456' })

React Hook

import { useSession } from '@superapp/auth'

function MyComponent() {
  const { data: session, isPending, error } = useSession()

  if (isPending) return <p>Loading...</p>
  if (!session) return <p>Not signed in</p>

  return <p>Welcome, {session.user.name}</p>
}

cURL Examples

# Sign in
curl -X POST http://localhost:3001/auth/sign-in \
  -H "Content-Type: application/json" \
  -d '{ "email": "alice@example.com", "password": "s3cure-passw0rd" }'

# Sign up
curl -X POST http://localhost:3001/auth/sign-up \
  -H "Content-Type: application/json" \
  -d '{ "email": "bob@example.com", "password": "s3cure-passw0rd", "name": "Bob" }'

# Get session
curl http://localhost:3001/auth/session \
  -H "Authorization: Bearer $TOKEN"

# Sign out
curl -X POST http://localhost:3001/auth/sign-out \
  -H "Authorization: Bearer $TOKEN"

# Forgot password
curl -X POST http://localhost:3001/auth/forgot-password \
  -H "Content-Type: application/json" \
  -d '{ "email": "alice@example.com" }'

On this page