# Client side session validation

**URL:** <https://forum.heroiclabs.com/t/client-side-session-validation/5382>\
**Category:** Client Libraries\
**Tags:** authentication, sdk-unity\
**Created:** [June 20, 2024, 4:29pm UTC](https://forum.heroiclabs.com/t/client-side-session-validation/5382 "2024-06-20T16:29:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirhoseinjfri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/amirhoseinjfri/32/1541_2.png) [@amirhoseinjfri](https://forum.heroiclabs.com/u/amirhoseinjfri)\
**Post date:** [June 20, 2024, 4:29pm UTC](https://forum.heroiclabs.com/t/client-side-session-validation/5382/1 "2024-06-20T16:29:34Z")

</div>

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

```auto
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 :

```auto
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 ?

```auto
 await client.GetAccountAsync(session);

```

thanks
