Client side session validation

hi is there any session validation check before trying to use like

var account = await client.GetAccountAsync(session);

inside unity ?

i mean if inside console i delete user then user try to use or connect any client function it will throw error 401 and because of that i need to use something like this :

private async void connectToSocketServer()
{
    try
    {
        UserSocket = Socket.From(client);
        await UserSocket.ConnectAsync(UserSession);
        Debug.Log("Socket connected!");
    }
    catch (ApiResponseException ex)
    {
        switch (ex.StatusCode)
        {
            case 401:
                PlayerPrefs.DeleteKey("nakama.session");
                authenticateDevice();
                break;
        }
    }
}

and it seems to me at least that this is not correct way to do this!. is there any suggestion or any other code that i don’t know ? what is correct way ? like using this function after getting session and try once within this function below ?

 await client.GetAccountAsync(session);

thanks