Player authentication
Talo player authentication manages logging players in, registering them and verifying them without needing to provision any of your own infrastructure. All of the examples below can be found in the authentication
sample from the Godot plugin.
Registering
To register a player, you can use Talo.player_auth.register()
. At a minimum, you need to provide a username and a password for the player.
If you want the player to be able to verify their logins via email (two factor authentication), you will also need to provide an email and set the verification_enabled
flag to true
.
@onready var username: TextEdit = %Username
@onready var password: TextEdit = %Password
@onready var enable_verification: CheckBox = %EnableVerification
@onready var email: TextEdit = %Email
@onready var validation_label: Label = %ValidationLabel
...
var res = await Talo.player_auth.register(username.text, password.text, email.text, enable_verification.button_pressed)
if res != OK:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.IDENTIFIER_TAKEN:
validation_label.text = "Username is already taken"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
Once a player is registered, a session will automatically be created for them and they will be logged in.
Logging in
To start a session, call the Talo.player_auth.login()
function with the username and password the player provided.
The login()
function returns a tuple of [Error, bool]
. The Error
refers to the result of the login operation and the bool
refers to whether the player needs to verify their details before creating the session.
signal verification_required
@onready var username: TextEdit = %Username
@onready var password: TextEdit = %Password
@onready var validation_label: Label = %ValidationLabel
...
var res = await Talo.player_auth.login(username.text, password.text)
if res[0] != OK:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.INVALID_CREDENTIALS:
validation_label.text = "Username or password is incorrect"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
else:
if res[1]:
verification_required.emit()
Verifying logins
If you need to verify a player's login, you need to call Talo.player_auth.verify()
with the code
sent to the player's email:
@onready var code: TextEdit = %Code
@onready var validation_label: Label = %ValidationLabel
...
var res = await Talo.player_auth.verify(code.text)
if res != OK:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.INVALID_CREDENTIALS:
validation_label.text = "Verification code is incorrect"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
Changing a player's password
To change the logged in player's password, you need to provide their current password and a new password to the Talo.player_auth.change_password()
function:
signal password_change_success
@onready var current_password: TextEdit = %CurrentPassword
@onready var new_password: TextEdit = %NewPassword
@onready var validation_label: Label = %ValidationLabel
...
var res = await Talo.player_auth.change_password(current_password.text, new_password.text)
if res != OK:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.INVALID_CREDENTIALS:
validation_label.text = "Current password is incorrect"
TaloAuthError.ErrorCode.NEW_PASSWORD_MATCHES_CURRENT_PASSWORD:
validation_label.text = "New password must be different from the current password"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
else:
password_change_success.emit()
Changing a player's email
You can also change a player's email with the Talo.player_auth.change_email()
function - just pass in their current password and a new email.