GitHub Documentation

Authorization in all rooms

  • I created an auth room where I load the player data from the database

        async onAuth(options) {
            //FIXME check fb auth key
            const data = await gameDao.fetchPlayer(options.uid);
            if (data.rows.length > 0) {
                return data.rows[0];
            return false;
        onJoin(client, options, auth) {
            var player = new Player(,;
            client.player = player;

    how to check in another room player data?

        // Code from play room
        async onAuth(options) {
            // this need check player data
            return false;

    for example, that players can not enter the location for high levels or the availability of game modes for premium players

  • administrator

    Hi @colyseus,

    You'd need to get the player's information during onAuth in every room he connects to. If you created a AuthRoom with the authentication method, you may want create the PlayRoom extending AuthRoom to have the exact same method.

    Something like this (I've wrote this quickly and haven't tested)

    export class PlayRoom extends AuthRoom {
      levelRequired = 5;
      async onAuth (options) {
        const data = await super.onAuth();
        if (data.level >= this.levelRequired) {
          return data;
        } else {
          return false;

    Not sure if that's your question. Let me know if that helps.


  • :astonished: this is suitable, thank you very much!


© 2021 Lucid Sight, Inc