Skip to content

Commit 333c171

Browse files
committed
add player auth migrate account api
1 parent 55f9647 commit 333c171

7 files changed

Lines changed: 57 additions & 5 deletions

File tree

Assets/Talo Game Services/Talo/Runtime/APIs/PlayerAuthAPI.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,19 @@ public async Task DeleteAccount(string currentPassword)
167167

168168
await _sessionManager.ClearSession();
169169
}
170+
171+
public async Task MigrateAccount(string currentPassword, string service, string identifier)
172+
{
173+
var uri = new Uri($"{baseUrl}/migrate");
174+
string content = JsonUtility.ToJson(new PlayerAuthMigrateAccountRequest {
175+
currentPassword = currentPassword,
176+
service = service,
177+
identifier = identifier
178+
});
179+
var json = await Call(uri, "POST", content);
180+
181+
var res = JsonUtility.FromJson<PlayerAuthMigrateAccountResponse>(json);
182+
await _sessionManager.HandleAccountMigrated(res);
183+
}
170184
}
171185
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace TaloGameServices
2+
{
3+
[System.Serializable]
4+
public class PlayerAuthMigrateAccountRequest
5+
{
6+
public string currentPassword;
7+
public string service;
8+
public string identifier;
9+
}
10+
}

Assets/Talo Game Services/Talo/Runtime/Requests/PlayerAuthMigrateAccountRequest.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace TaloGameServices
2+
{
3+
[System.Serializable]
4+
public class PlayerAuthMigrateAccountResponse
5+
{
6+
public PlayerAlias alias;
7+
}
8+
}

Assets/Talo Game Services/Talo/Runtime/Responses/PlayerAuthMigrateAccountResponse.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Talo Game Services/Talo/Runtime/Utils/PlayerAuthException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public enum PlayerAuthErrorCode {
1515
PASSWORD_RESET_CODE_INVALID,
1616
VERIFICATION_EMAIL_REQUIRED,
1717
INVALID_EMAIL,
18-
NEW_IDENTIFIER_MATCHES_CURRENT_IDENTIFIER
18+
NEW_IDENTIFIER_MATCHES_CURRENT_IDENTIFIER,
19+
INVALID_MIGRATION_TARGET
1920
}
2021

2122
public class PlayerAuthException : Exception

Assets/Talo Game Services/Talo/Runtime/Utils/SessionManager.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ private void SaveSession(string sessionToken)
2626
SetIdentifierPlayerPref();
2727
}
2828

29-
public async Task ClearSession()
29+
public async Task ClearSession(bool resetSocket = true)
3030
{
3131
Talo.CurrentAlias = null;
3232
PlayerPrefs.DeleteKey("TaloSessionToken");
33-
await Talo.Socket.ResetConnection();
33+
if (resetSocket)
34+
{
35+
await Talo.Socket.ResetConnection();
36+
}
3437
}
3538

3639
public string GetSessionToken()
@@ -48,11 +51,23 @@ public bool CheckForSession()
4851
return !string.IsNullOrEmpty(GetSessionToken());
4952
}
5053

54+
private void SetNewAlias(PlayerAlias alias)
55+
{
56+
Talo.CurrentAlias = alias;
57+
alias.WriteOfflineAlias();
58+
}
59+
5160
public void HandleIdentifierUpdated(PlayerAuthChangeIdentifierResponse res)
5261
{
53-
Talo.CurrentAlias = res.alias;
54-
Talo.CurrentAlias.WriteOfflineAlias();
62+
SetNewAlias(res.alias);
5563
SetIdentifierPlayerPref();
5664
}
65+
66+
public async Task HandleAccountMigrated(PlayerAuthMigrateAccountResponse res)
67+
{
68+
await ClearSession(false);
69+
SetNewAlias(res.alias);
70+
Talo.Players.InvokeIdentifiedEvent();
71+
}
5772
}
5873
}

0 commit comments

Comments
 (0)