Auth API (Draft WIP) - lolmaxz/vrc-ts GitHub Wiki

Certainly! Here's the updated Auth API Documentation with collapsible sections using <details> and <summary> tags to make it easier to digest.

Auth API Documentation

The Auth API allows you to manage authentication-related tasks such as retrieving the current user information, verifying two-factor authentication codes, checking user existence, and logging out.


Index

  1. getCurrentUser - Get information about the currently authenticated user.

  2. userExist - Check if a user exists by username, display name, or email.

  3. verify2FACodeTOTP - Verify a two-factor authentication code using TOTP.

  4. verify2FAEmailCode - Verify a two-factor authentication code sent via email.

  5. verifyAuthToken - Verify if the current authentication token is valid.

  6. logout - Log out of the current session.


Endpoints

1. getCurrentUser

Get information about the currently authenticated user.

Purpose

Get information about the currently authenticated user.

Method Signature

getCurrentUser(): Promise<CurrentUser>

Parameters

  • None

Returns

  • Promise<CurrentUser>: A promise that resolves to a CurrentUser object containing detailed information about the authenticated user.

Example Usage

// Example: Get information about the current user
const currentUser = await vrchatApi.authApi.getCurrentUser();
console.log(currentUser);

2. userExist

Check if a user exists by username, display name, or email.

Purpose

Check if a user exists by username, display name, or email.

Method Signature

userExist(params: {
  email?: string;
  displayName?: string;
  userId?: string;
  excludeUserId?: string;
}): Promise<{ userExists: boolean; nameOk: boolean }>

Parameters

  • params (object):

    At least one of the following fields is required:

    • email (string, optional):
      The email address to check.

    • displayName (string, optional):
      The display name to check.

    • userId (string, optional):
      The user ID to check.

    Optional field:

    • excludeUserId (string, optional):
      Exclude a specific user ID from the check (useful when changing your own display name or email to prevent self-conflict).

Returns

  • Promise<{ userExists: boolean; nameOk: boolean }>: A promise that resolves to an object indicating whether the user exists and if the name is acceptable.

Example Usage

// Example: Check if a username is available
const result = await vrchatApi.authApi.userExist({ displayName: 'NewDisplayName' });
console.log(result); // { userExists: false, nameOk: true }

// Example: Check if an email is already in use
const emailCheck = await vrchatApi.authApi.userExist({ email: '[email protected]' });
console.log(emailCheck); // { userExists: true, nameOk: false }

3. verify2FACodeTOTP

Verify a two-factor authentication code using TOTP.

Purpose

Verify a two-factor authentication code using Time-based One-Time Password (TOTP).

Method Signature

verify2FACodeTOTP(): Promise<{ verified: boolean }>

Parameters

  • None

    This method uses the 2FA code from the environment variable TOTP_2FA_CODE or generates one using the VRCHAT_2FA_SECRET if provided.

Returns

  • Promise<{ verified: boolean }>: A promise that resolves to an object indicating whether the 2FA verification was successful.

Example Usage

// Example: Verify 2FA code using TOTP
const verificationResult = await vrchatApi.authApi.verify2FACodeTOTP();
console.log(verificationResult); // { verified: true }

Note: Ensure that you have set the environment variable TOTP_2FA_CODE or VRCHAT_2FA_SECRET before using this method.


4. verify2FAEmailCode

Verify a two-factor authentication code sent via email.

Purpose

Verify a two-factor authentication code sent via email.

Method Signature

verify2FAEmailCode(): Promise<{ verified: boolean }>

Parameters

  • None

    This method uses the 2FA code from the environment variable EMAIL_2FA_CODE.

Returns

  • Promise<{ verified: boolean }>: A promise that resolves to an object indicating whether the 2FA verification was successful.

Example Usage

// Example: Verify 2FA code received via email
const verificationResult = await vrchatApi.authApi.verify2FAEmailCode();
console.log(verificationResult); // { verified: true }

Note: Ensure that you have set the environment variable EMAIL_2FA_CODE with the code received via email before using this method.


5. verifyAuthToken

Verify if the current authentication token is valid.

Purpose

Verify if the current authentication token is valid.

Method Signature

verifyAuthToken(): Promise<{ ok: boolean; token: string }>

Parameters

  • None

Returns

  • Promise<{ ok: boolean; token: string }>: A promise that resolves to an object indicating whether the token is valid and returns the token.

Example Usage

// Example: Verify the authentication token
const authStatus = await vrchatApi.authApi.verifyAuthToken();
console.log(authStatus); // { ok: true, token: 'auth_token_string' }

6. logout

Log out of the current session.

Purpose

Log out of the current session.

Method Signature

logout(): Promise<{ success: { message: string; status_code: number } }>

Parameters

  • None

Returns

  • Promise<{ success: { message: string; status_code: number } }>: A promise that resolves to a success message upon logging out.

Example Usage

// Example: Log out of the current session
const logoutResult = await vrchatApi.authApi.logout();
console.log(logoutResult); // { success: { message: 'Success', status_code: 200 } }

Note: Some methods require environment variables to be set for them to function correctly. Ensure you have configured your environment variables as needed.


⚠️ **GitHub.com Fallback** ⚠️