colyseus / colyseus-unity-sdk

⚔ Colyseus Multiplayer SDK for Unity
https://docs.colyseus.io/getting-started/unity-sdk/
MIT License
371 stars 100 forks source link

Auth API #220

Closed endel closed 7 months ago

endel commented 7 months ago

Overview for Auth API:

Define callback for Auth state change:

client.Auth.OnChange((Colyseus.AuthData<User> authData) =>
{
    if (authData.user != null)
    {
        // Logged in!
    }
    else
    {
        // Logged out!
    }
});

Methods:

Example

class User
{
    public int id;
    public string email;
    public string name;
}

// ...

try
{
    var response = await client.Auth.SignInWithEmailAndPassword<User>("endel@colyseus.io", "123456");
    Debug.Log(response.user.id);
    Debug.Log(response.user.email);
    Debug.Log(response.user.name);
}
catch (Colyseus.HttpException e)
{
    // e.Message
    // e.StatusCode
}
yty commented 1 month ago

Can you provide a complete example of Auth?