Skip to content
On this page

mongoId

  • Property: mongoId
  • Type: string
  • Optional: true
  • Read Only
  • Usage:

The player's MongoDB ID.


onAuthSuccess

  • Since: 4.0.0
  • Property: onAuthSuccess
  • Type: (player: RpgPlayer, dbData: object | undefined) => void
  • Optional: true
  • Arguments:
    • { RpgPlayer} player. - The RPG player object. (Optional: false)
    • {object | undefined} dbData. - Optional database data related to the player. If no data, then this is the first time the player has arrived, or he has no save. (Optional: false)
  • Return: void
  • Example:
ts
import { RpgPlayer, RpgPlayerHooks } from '@rpgjs/server'

const player: RpgPlayerHooks = {
   onAuthSuccess(player: RpgPlayer) {
         console.log('player auth')
   }
}
  • Usage:

This method is called at the end of authentication, when everything has worked.


canAuth

  • Since: 4.0.0
  • Property: canAuth
  • Type: (player: RpgPlayer, dbData: object | undefined, gui: Gui) => Promise | void | Promise | boolean
  • Optional: true
  • Arguments:
    • { RpgPlayer} player. - The RPG player object. (Optional: false)
    • {object | undefined} dbData. - Optional database data related to the player. If no data, then this is the first time the player has arrived, or he has no save. (Optional: false)
    • {Gui} gui. - The GUI object. Represents the authentication box (Optional: false)
  • Return: Promise | void | Promise | boolean Promise or a boolean value (true/false) or nothing (void).
  • If the method returns a Promise, it indicates asynchronous processing.
  • If the return is false, then you block the rest, the player is not loaded.
  • Example:
ts
import { RpgPlayer, RpgPlayerHooks } from '@rpgjs/server'

const player: RpgPlayerHooks = {
  canAuth(player: RpgPlayer) {
     console.log('player auth')
     // If you return false, the player is not loaded
     return false
 }
}
  • Usage:

this method provides an additional check before loading the data


onAuthFailed

  • Since: 4.0.0
  • Property: onAuthFailed
  • Type: (player: RpgPlayer, error: Error) => void
  • Optional: true
  • Arguments:
    • { RpgPlayer} player. - The RPG player object. (Optional: false)
    • {Error} error. - The error object representing the reason for authentication failure. (Optional: false)
  • Example:
ts
import { RpgPlayer, RpgPlayerHooks } from '@rpgjs/server'

const player: RpgPlayerHooks = {
  onAuthFailed(player: RpgPlayer, error: Error) {
    console.log('player auth failed')
 }
}
  • Usage:

This method is called when authentication fails for the player.