The User API enables developers to get general information about the current user.
All features are accessible via the heyVR.user object. This object offers the following methods that you can use:
The following method allows developers to check whether a user is logged in to their account.
heyVR.user.isLoggedIn() : Promise<boolean>
Promise<boolean>). If there's a network error, the promise will be rejected with a response object error and a debug string of err_network, accessible at response.status.debugThe following method allows developers to retrieve the name of a user that is logged in to their account
heyVR.user.getName() : Promise<string>
Promise<string>) or rejected if user is not logged inThis method allows developers to check how many coins the user owns, e.g. to indicate which items can be bought without topping up on coins.
heyVR.user.getAmountCoins() : Promise<number>
Promise<number>) or rejected if user is not logged inThe following method will exit the VR mode and open the login/registration modal to allow the users to log into their account. Developers will have access to the result of user's choice.
heyVR.user.openLogin() : Promise<{
username:string;
alias:string;
action:'register'|'login'
}>
if your game depends on the user's authentication status ( for example, offers inventory items, leaderboards, progress save, etc. ) You can listen to whenever a user logs in or out of heyVR.
You can do so by registering a callback:
heyVR.user.onAuthChange( callback:( e: OnAuthMessage ) => void ): void;
The callback function will receive the following object everytime:
{
viaSDK: boolean; // Whether the login was initiated openLogin() or not
loggedIn: boolean; // Whether the user is now logged in or out
username: string; // User's username
alias: string; // User's alias, might be an empty string
}
You can also removed the registered event listener the following way:
heyVR.user.removeOnAuthChange( callback ): void;
The callback parameter is the callback function you've registered earlier.
To trigger an authentication change in sandbox, you can use the following method:
heyVR.user.setLoginStatus( loggedIn: boolean, viaSDK?: boolean ): void;
This method is only available in the sandbox SDK.
loggedIn: Required. The new login status. Required.viaSDK: Sets the viaSDK value for the onAuthChange callback.Whenever a user's balance is updated, either due to purchasing more coins or purchaging an item, you can listen to an event that is triggered after this:
heyVR.user.onCoinChange( callback: ( balance: number ) => void ): void;
Your provided callback will be called, and user's current balance will be passed to it as an integer.