Skip to content

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 ​

ts
new AccountClient(options?): AccountClient;

Defined in: client/accounts.ts:146

Parameters ​

ParameterType
options?AccountClientOptions

Returns ​

AccountClient

Properties ​

PropertyModifierTypeDescriptionDefined in
tokenSourcereadonlyTokenSourceFor 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 ​

ts
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 ​

ts
get signedIn(): boolean;

Defined in: client/accounts.ts:163

Whether someone is signed in.

Returns ​

boolean


playerId ​

Get Signature ​

ts
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() ​

ts
onChange(listener): () => void;

Defined in: client/accounts.ts:173

Calls listener whenever the signed-in account changes. Returns a function that stops it.

Parameters ​

ParameterType
listener(account) => void

Returns ​

() => void


restore() ​

ts
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() ​

ts
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 ​

ParameterType
input{ name: string; password: string; email?: string; }
input.namestring
input.passwordstring
input.email?string

Returns ​

Promise<Account>


login() ​

ts
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 ​

ParameterType
namestring
passwordstring

Returns ​

Promise<Account>


logout() ​

ts
logout(): Promise<void>;

Defined in: client/accounts.ts:212

Ends the session, on the server and here.

Returns ​

Promise<void>


changePassword() ​

ts
changePassword(current, next): Promise<void>;

Defined in: client/accounts.ts:222

Changes the password. Every other session of the account is signed out.

Parameters ​

ParameterType
currentstring
nextstring

Returns ​

Promise<void>


createRecoveryCode() ​

ts
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 ​

ParameterType
passwordstring

Returns ​

Promise<string>


recover() ​

ts
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 ​

ParameterType
namestring
codestring
passwordstring

Returns ​

Promise<Account>


forgotPassword() ​

ts
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 ​

ParameterType
who| { name: string; } | { email: string; }

Returns ​

Promise<void>


resetPassword() ​

ts
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 ​

ParameterType
tokenstring
passwordstring

Returns ​

Promise<Account>


rename() ​

ts
rename(name): Promise<Account>;

Defined in: client/accounts.ts:269

Takes another name.

Parameters ​

ParameterType
namestring

Returns ​

Promise<Account>


setEmail() ​

ts
setEmail(password, email): Promise<Account>;

Defined in: client/accounts.ts:276

Sets the email address, or removes it with null. Needs the password.

Parameters ​

ParameterType
passwordstring
emailstring | null

Returns ​

Promise<Account>


deleteAccount() ​

ts
deleteAccount(password): Promise<void>;

Defined in: client/accounts.ts:283

Deletes the account and everything stored with it.

Parameters ​

ParameterType
passwordstring

Returns ​

Promise<void>


exportData() ​

ts
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() ​

ts
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() ​

ts
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 ​

ParameterType
scope?string

Returns ​

Promise<string>


getData() ​

ts
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 ParameterDefault type
Tunknown

Parameters ​

ParameterType
keystring

Returns ​

Promise<T | undefined>


setData() ​

ts
setData(key, value): Promise<void>;

Defined in: client/accounts.ts:338

Stores a value under a key the game lets players write.

Parameters ​

ParameterType
keystring
valueunknown

Returns ​

Promise<void>


deleteData() ​

ts
deleteData(key): Promise<void>;

Defined in: client/accounts.ts:344

Removes a value under a key the game lets players write.

Parameters ​

ParameterType
keystring

Returns ​

Promise<void>


profile() ​

ts
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 ​

ParameterType
playerIdstring

Returns ​

Promise<Profile | null>


leaderboard() ​

ts
leaderboard(stat, page?): Promise<Leaderboard>;

Defined in: client/accounts.ts:363

A page of the leaderboard for stat, highest first.

Parameters ​

ParameterType
statstring
page?{ limit?: number; offset?: number; }
page.limit?number
page.offset?number

Returns ​

Promise<Leaderboard>

MIT licence. Tickflare is an independent project and is not affiliated with Cloudflare.