diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs index 831fe55..b226f82 100644 --- a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs @@ -74,8 +74,7 @@ public async Task Logout() var uri = new Uri($"{baseUrl}/logout"); await Call(uri, "POST"); - _sessionManager.ClearSession(); - Talo.CurrentAlias = null; + await _sessionManager.ClearSession(); } public async Task ChangePassword(string currentPassword, string newPassword) @@ -136,8 +135,7 @@ public async Task DeleteAccount(string currentPassword) }); await Call(uri, "DELETE", content); - _sessionManager.ClearSession(); - Talo.CurrentAlias = null; + await _sessionManager.ClearSession(); } } } diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayersAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayersAPI.cs index a4aed18..21a211e 100644 --- a/Assets/Talo Game Services/Talo/Runtime/APIs/PlayersAPI.cs +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/PlayersAPI.cs @@ -21,6 +21,7 @@ public async Task Identify(string service, string identifier) var json = await Call(uri, "GET"); var res = JsonUtility.FromJson(json); + await Talo.Socket.ResetConnection(); Talo.CurrentAlias = res.alias; Talo.Socket.SetSocketToken(res.socketToken); diff --git a/Assets/Talo Game Services/Talo/Runtime/TaloSocket.cs b/Assets/Talo Game Services/Talo/Runtime/TaloSocket.cs index 84abca6..a705b65 100644 --- a/Assets/Talo Game Services/Talo/Runtime/TaloSocket.cs +++ b/Assets/Talo Game Services/Talo/Runtime/TaloSocket.cs @@ -116,5 +116,18 @@ public void SetSocketToken(string token) IdentifyPlayer(); } } + + public async Task ResetConnection() + { + if (!identified) + { + return; + } + + CloseConnection(); + socketAuthenticated = false; + identified = false; + await OpenConnection(); + } } } diff --git a/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs b/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs index 41d86d3..6dea232 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System.Threading.Tasks; +using UnityEngine; namespace TaloGameServices { @@ -20,9 +21,11 @@ private void SaveSession(string sessionToken) PlayerPrefs.SetString("TaloSessionIdentifier", Talo.CurrentAlias.identifier); } - public void ClearSession() + public async Task ClearSession() { + Talo.CurrentAlias = null; PlayerPrefs.DeleteKey("TaloSessionToken"); + await Talo.Socket.ResetConnection(); } public string GetSessionToken()