Skip to main content

User

User.getCurrent(): Promise<CastleUser>​

Returns the signed-in player. Throws CastleError (LOGIN_REQUIRED) when nobody is signed in.

A CastleUser has userId, username, isAnonymous, isActive, photoUrl (their 256px avatar), frameUrl (the 96px frame drawn around it) and color (the hex their username is shown in); the last three are null when unset. The urls are data: urls, so they go straight into an <img> or a texture. Anonymous accounts are real logins with generated anonymous-user-... names; check isAnonymous before accepting writes into anything other players see, such as a shared gallery.

const me = await User.getCurrent();
greet(me.username);

User.get(userId): Promise<CastleUser | null>​

Another player as anyone may see them, or null when no such user exists. Results are cached per id for the life of the page. The ids come from the session's player list or from Store.user(id) rows.

const them = await User.get(player.userId);
if (them?.photoUrl) {
avatar.src = them.photoUrl;
}