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.
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.
-
getCurrentUser
- Get information about the currently authenticated user. -
userExist
- Check if a user exists by username, display name, or email. -
verify2FACodeTOTP
- Verify a two-factor authentication code using TOTP. -
verify2FAEmailCode
- Verify a two-factor authentication code sent via email. -
verifyAuthToken
- Verify if the current authentication token is valid. -
logout
- Log out of the current session.
Get information about the currently authenticated user.
Get information about the currently authenticated user.
getCurrentUser(): Promise<CurrentUser>
- None
-
Promise<CurrentUser>
: A promise that resolves to aCurrentUser
object containing detailed information about the authenticated user.
// Example: Get information about the current user
const currentUser = await vrchatApi.authApi.getCurrentUser();
console.log(currentUser);
Check if a user exists by username, display name, or email.
Check if a user exists by username, display name, or email.
userExist(params: {
email?: string;
displayName?: string;
userId?: string;
excludeUserId?: string;
}): Promise<{ userExists: boolean; nameOk: boolean }>
-
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).
-
-
Promise<{ userExists: boolean; nameOk: boolean }>
: A promise that resolves to an object indicating whether the user exists and if the name is acceptable.
// 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 }
Verify a two-factor authentication code using TOTP.
Verify a two-factor authentication code using Time-based One-Time Password (TOTP).
verify2FACodeTOTP(): Promise<{ verified: boolean }>
-
None
This method uses the 2FA code from the environment variable
TOTP_2FA_CODE
or generates one using theVRCHAT_2FA_SECRET
if provided.
-
Promise<{ verified: boolean }>
: A promise that resolves to an object indicating whether the 2FA verification was successful.
// 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.
Verify a two-factor authentication code sent via email.
Verify a two-factor authentication code sent via email.
verify2FAEmailCode(): Promise<{ verified: boolean }>
-
None
This method uses the 2FA code from the environment variable
EMAIL_2FA_CODE
.
-
Promise<{ verified: boolean }>
: A promise that resolves to an object indicating whether the 2FA verification was successful.
// 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.
Verify if the current authentication token is valid.
Verify if the current authentication token is valid.
verifyAuthToken(): Promise<{ ok: boolean; token: string }>
- None
-
Promise<{ ok: boolean; token: string }>
: A promise that resolves to an object indicating whether the token is valid and returns the token.
// Example: Verify the authentication token
const authStatus = await vrchatApi.authApi.verifyAuthToken();
console.log(authStatus); // { ok: true, token: 'auth_token_string' }
Log out of the current session.
Log out of the current session.
logout(): Promise<{ success: { message: string; status_code: number } }>
- None
-
Promise<{ success: { message: string; status_code: number } }>
: A promise that resolves to a success message upon logging out.
// 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.