-
I feel very stupid but i can't see how to set the player's name once it's authenticated. static async onAuth (token: string, request: any) {
const res = await jwt.verify(token, SECRET);
if (!res) {
throw new ServerError(400, "bad access token");
}
return res;
}
onJoin (client: Client, options: any) {
this.state.players.set(client.sessionId, new Player());
client.userData = {
username: client.auth.username
};
console.log(client.auth.username, "joined!");
} But turns out that |
Beta Was this translation helpful? Give feedback.
Answered by
endel
Jan 6, 2024
Replies: 1 comment 1 reply
-
Hi @psociety, the class Player extends Schema {
@type("string") username: string;
}
// ...
onJoin(client, options) {
this.state.players.set(client.sessionId, new Player().assign({
username: client.auth.username
}));
console.log(client.auth.username, "joined!");
} Reading it from the client-side: const room = await client.joinOrCreate("my_room");
room.state.players.onAdd((player, sessionId) => {
console.log(player.username, "joined!");
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
psociety
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @psociety, the
client.userData
is meant for server usage only, the only structures that are synchronized automatically are from the room's state. You can do it like this:Reading it from the client-side: