Define callback for Auth state change:
client.Auth.OnChange((Colyseus.AuthData<User> authData) =>
{
if (authData.user != null)
{
// Logged in!
}
else
{
// Logged out!
}
});
Methods:
client.Auth.RegisterWithEmailAndPassword()
client.Auth.SignInWithEmailAndPassword()
client.Auth.SignInAnonymously()
client.Auth.SendResetPasswordEmail()
client.Auth.SignOut()
- (❌ OAuth not yet implemented)
client.Auth.SignInWithProvider()
Example
class User
{
public int id;
public string email;
public string name;
}
// ...
try
{
var response = await client.Auth.SignInWithEmailAndPassword<User>("[email protected]", "123456");
Debug.Log(response.user.id);
Debug.Log(response.user.email);
Debug.Log(response.user.name);
}
catch (Colyseus.HttpException e)
{
// e.Message
// e.StatusCode
}