Class: AccountClient
Defined in: client/accounts.ts:134
The client side of Accounts: a guest identity until the player signs up, sign-up and sign-in, the player's own data, profiles and leaderboards.
const accounts = new AccountClient();
await accounts.restore();
const room = new RoomClient(url, { token: accounts.tokenSource });
Constructors
Constructor
new AccountClient(options?): AccountClient;Defined in: client/accounts.ts:146
Parameters
| Parameter | Type |
|---|---|
options? | AccountClientOptions |
Returns
AccountClient
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
tokenSource | readonly | TokenSource | For RoomClient's token option: a join token for the signed-in player, or the guest's token for anyone else. | client/accounts.ts:322 |
Accessors
account
Get Signature
get account(): Account | null;Defined in: client/accounts.ts:158
The signed-in account, once restore, login or register has found one.
Returns
Account | null
signedIn
Get Signature
get signedIn(): boolean;Defined in: client/accounts.ts:163
Whether someone is signed in.
Returns
boolean
playerId
Get Signature
get playerId(): string | undefined;Defined in: client/accounts.ts:168
The player id to use: the account's, else the guest's, else undefined.
Returns
string | undefined
Methods
onChange()
onChange(listener): () => void;Defined in: client/accounts.ts:173
Calls listener whenever the signed-in account changes. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
listener | (account) => void |
Returns
() => void
restore()
restore(): Promise<Account | null>;Defined in: client/accounts.ts:179
Finds out whether a session is still good. Call once at startup.
Returns
Promise<Account | null>
register()
register(input): Promise<Account>;Defined in: client/accounts.ts:193
Creates an account and signs in. A guest who registers keeps their player id.
Parameters
| Parameter | Type |
|---|---|
input | { name: string; password: string; email?: string; } |
input.name | string |
input.password | string |
input.email? | string |
Returns
Promise<Account>
login()
login(name, password): Promise<Account>;Defined in: client/accounts.ts:204
Signs in. Rejects with AccountRequestError (invalid_credentials, too_many_attempts) if it cannot.
Parameters
| Parameter | Type |
|---|---|
name | string |
password | string |
Returns
Promise<Account>
logout()
logout(): Promise<void>;Defined in: client/accounts.ts:212
Ends the session, on the server and here.
Returns
Promise<void>
changePassword()
changePassword(current, next): Promise<void>;Defined in: client/accounts.ts:222
Changes the password. Every other session of the account is signed out.
Parameters
| Parameter | Type |
|---|---|
current | string |
next | string |
Returns
Promise<void>
createRecoveryCode()
createRecoveryCode(password): Promise<string>;Defined in: client/accounts.ts:233
Makes a recovery code and returns it: show it to the player once, to keep somewhere safe. It sets a new password with recover, with no email involved, and replaces the code the account had. Needs the password.
Parameters
| Parameter | Type |
|---|---|
password | string |
Returns
Promise<string>
recover()
recover(
name,
code,
password
): Promise<Account>;Defined in: client/accounts.ts:243
Sets a new password with a recovery code, and signs in. The code is used up. Rejects with AccountRequestError (invalid_code, too_many_attempts).
Parameters
| Parameter | Type |
|---|---|
name | string |
code | string |
password | string |
Returns
Promise<Account>
forgotPassword()
forgotPassword(who): Promise<void>;Defined in: client/accounts.ts:256
Asks for a password reset link to be sent to the account with this name, or to every account with this email address. It resolves whether or not there is such an account, so as not to tell. Rejects with not_enabled if the game does not send email.
Parameters
| Parameter | Type |
|---|---|
who | | { name: string; } | { email: string; } |
Returns
Promise<void>
resetPassword()
resetPassword(token, password): Promise<Account>;Defined in: client/accounts.ts:261
Sets a new password with the token from a reset link, and signs in. Rejects with invalid_token.
Parameters
| Parameter | Type |
|---|---|
token | string |
password | string |
Returns
Promise<Account>
rename()
rename(name): Promise<Account>;Defined in: client/accounts.ts:269
Takes another name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Promise<Account>
setEmail()
setEmail(password, email): Promise<Account>;Defined in: client/accounts.ts:276
Sets the email address, or removes it with null. Needs the password.
Parameters
| Parameter | Type |
|---|---|
password | string |
email | string | null |
Returns
Promise<Account>
deleteAccount()
deleteAccount(password): Promise<void>;Defined in: client/accounts.ts:283
Deletes the account and everything stored with it.
Parameters
| Parameter | Type |
|---|---|
password | string |
Returns
Promise<void>
exportData()
exportData(): Promise<Record<string, unknown>>;Defined in: client/accounts.ts:290
Everything the server keeps about the signed-in player.
Returns
Promise<Record<string, unknown>>
guest()
guest(): Promise<Guest>;Defined in: client/accounts.ts:299
A guest identity, made on first use and kept in storage. Its token is renewed, for the same player id, once it is half way to expiring; a guest who stays away until it has expired starts over as a new player.
Returns
Promise<Guest>
joinToken()
joinToken(scope?): Promise<string>;Defined in: client/accounts.ts:313
A short-lived join token for a room or queue, for the signed-in player.
Parameters
| Parameter | Type |
|---|---|
scope? | string |
Returns
Promise<string>
getData()
getData<T>(key): Promise<T | undefined>;Defined in: client/accounts.ts:328
The signed-in player's value under key, or undefined.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<T | undefined>
setData()
setData(key, value): Promise<void>;Defined in: client/accounts.ts:338
Stores a value under a key the game lets players write.
Parameters
| Parameter | Type |
|---|---|
key | string |
value | unknown |
Returns
Promise<void>
deleteData()
deleteData(key): Promise<void>;Defined in: client/accounts.ts:344
Removes a value under a key the game lets players write.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<void>
profile()
profile(playerId): Promise<Profile | null>;Defined in: client/accounts.ts:353
A player's public profile, or null if there is no such account.
Parameters
| Parameter | Type |
|---|---|
playerId | string |
Returns
Promise<Profile | null>
leaderboard()
leaderboard(stat, page?): Promise<Leaderboard>;Defined in: client/accounts.ts:363
A page of the leaderboard for stat, highest first.
Parameters
| Parameter | Type |
|---|---|
stat | string |
page? | { limit?: number; offset?: number; } |
page.limit? | number |
page.offset? | number |
Returns
Promise<Leaderboard>