RegisterLogin
DocsPricing
RegisterLogin
  • Getting Started
  • Introduction
  • Quick Start
  • SDKs
  • React
  • TypeScript
  • Next.js
  • Express
  • NestJS
  • Python
  • API Reference
  • Support and Resources
  • FAQ
  • Contact Support

AuthSafe

Product

HighlightFeatureIntegrationPricingFAQ

Company

AboutBlogContactSitemap

Developer

DashboardDocumentation

Legal

Terms & ConditionsPrivacyComplianceShippingCancellation

© 2026 AuthSafe. All rights reserved.

We value your privacy

This website uses cookies for anonymous analytics to help us improve your experience. No personal information is stored or shared. You can allow or reject analytics tracking at any time. See our Privacy Policy.

We use cookies for anonymous analytics. No personal info is stored. See our Privacy Policy.

UserApi

API client for user profile management and account operations.

Constructor

import { HttpService, UserApi } from 'authsafe-ts';

const user = await oauthService.getUser();
const httpService = new HttpService(user?.access_token);
const userApi = new UserApi(httpService);

Methods

Get User Profile

Fetch detailed user information.
await userApi.getUser(userId: string): Promise<UserProfile>
Returns:
interface UserProfile {
  id: string;
  email: string;
  name?: string;
  picture?: string;
  email_verified: boolean;
  created_at: string;
  updated_at: string;
  metadata?: Record<string, any>;
}
Example:
const profile = await userApi.getUser('user-123');
console.log('User:', profile.name, profile.email);

Update User Profile

Update user information (name, metadata, etc.).
await userApi.updateUser(userId: string, data: Partial<UserProfile>): Promise<UserProfile>
Example:
const updated = await userApi.updateUser('user-123', {
  name: 'John Doe',
  metadata: { company: 'Acme Corp' },
});

Change Password

Update user's password.
await userApi.changePassword(
  userId: string,
  currentPassword: string,
  newPassword: string
): Promise<{ success: boolean; message: string }>
Example:
try {
  const result = await userApi.changePassword(
    'user-123',
    'currentPass123',
    'newSecurePass456',
  );

  if (result.success) {
    console.log('Password changed successfully');
  }
} catch (error) {
  console.error('Password change failed:', error.message);
}

Delete User

Permanently delete a user account.
await userApi.deleteUser(userId: string): Promise<{ success: boolean }>
Example:
const result = await userApi.deleteUser('user-123');

if (result.success) {
  console.log('Account deleted');
  await oauthService.signoutRedirect();
}

List Users (Admin)

Get all users in the tenant (requires admin privileges).
await userApi.listUsers(params?: {
  page?: number;
  limit?: number;
  search?: string;
}): Promise<{
  users: UserProfile[];
  total: number;
  page: number;
  limit: number;
}>
Example:
const { users, total } = await userApi.listUsers({
  page: 1,
  limit: 20,
  search: 'john',
});

console.log(`Found ${total} users`);

Complete Examples

Profile Management

import { OAuthService, HttpService, UserApi } from 'authsafe-ts';

// Initialize
const oauthService = new OAuthService({ clientId, redirectUri });
const user = await oauthService.getUser();
const httpService = new HttpService(user?.access_token);
const userApi = new UserApi(httpService);

// Get current user profile
const userId = user?.profile.sub;
const profile = await userApi.getUser(userId);

console.log('Current profile:', profile);

// Update profile
const updated = await userApi.updateUser(userId, {
  name: 'Jane Smith',
  metadata: {
    department: 'Engineering',
    role: 'Developer',
  },
});

console.log('Updated profile:', updated);

Password Change

async function handlePasswordChange(currentPwd: string, newPwd: string) {
  const user = await oauthService.getUser();
  const httpService = new HttpService(user?.access_token);
  const userApi = new UserApi(httpService);

  try {
    const result = await userApi.changePassword(
      user.profile.sub,
      currentPwd,
      newPwd,
    );

    if (result.success) {
      alert('Password changed successfully');
    }
  } catch (error) {
    if (error.message.includes('incorrect')) {
      alert('Current password is incorrect');
    } else {
      alert('Password change failed');
    }
  }
}

Account Deletion

async function deleteAccount() {
  const confirmed = confirm('Are you sure? This action cannot be undone.');

  if (!confirmed) return;

  const user = await oauthService.getUser();
  const httpService = new HttpService(user?.access_token);
  const userApi = new UserApi(httpService);

  try {
    await userApi.deleteUser(user.profile.sub);

    // Logout after deletion
    await oauthService.signoutRedirect();
  } catch (error) {
    console.error('Account deletion failed:', error);
  }
}

Related

  • MfaApi - MFA management
  • OAuthService - Authentication
  • Utilities - Password strength checker