https and auth token rollover

This commit is contained in:
2026-04-25 00:58:07 +05:30
parent 217dacb54c
commit 8bc14d5fff
9 changed files with 1159 additions and 76 deletions
+53 -5
View File
@@ -13,7 +13,7 @@ using UnityEngine.UI;
public class LoginManager : MonoBehaviour
{
public const string AuthBaseUrl = "http://vps.playpoolstudios.com:2612";
public const string AuthBaseUrl = "https://kickkingsapi.playpoolstudios.com";
const string PlayerPrefsAuthKey = "WalkInvest.AuthToken";
const int MIN_USERNAME_LENGTH = 3;
@@ -93,6 +93,9 @@ public class LoginManager : MonoBehaviour
}
instance = this;
DontDestroyOnLoad(gameObject);
if (string.IsNullOrEmpty(AuthToken))
ClearLocalUserProfile();
}
void Start()
@@ -143,11 +146,43 @@ public class LoginManager : MonoBehaviour
IEnumerator ResumeSessionCoroutine()
{
yield return StartCoroutine(FetchUserDataCoroutine(null, true));
ProceedToMainMenu();
ClearLocalUserProfile();
bool ok = false;
string errMsg = null;
yield return StartCoroutine(FetchUserDataCoroutine((success, err, _) =>
{
ok = success;
errMsg = err;
}, true));
if (ok)
ProceedToMainMenu();
else
{
InvalidateStoredSession();
if (error_txt != null)
error_txt.text = string.IsNullOrEmpty(errMsg) ? "Session expired. Please sign in again." : errMsg;
}
SetBusy(false);
}
/// <summary>Clears cached profile only (token unchanged). Call when leaving a broken state without wiping prefs.</summary>
static void ClearLocalUserProfile()
{
_currentUser = null;
}
/// <summary>Removes auth token from memory and disk and clears cached profile (login screen recovery).</summary>
static void InvalidateStoredSession()
{
AuthToken = "";
ClearLocalUserProfile();
ClearMatchYourTeam();
PlayerPrefs.DeleteKey(PlayerPrefsAuthKey);
PlayerPrefs.Save();
}
static void ProceedToMainMenu()
{
if (LevelLoadManager.instance != null)
@@ -230,6 +265,7 @@ public class LoginManager : MonoBehaviour
{
SetBusy(true);
error_txt.text = "";
ClearLocalUserProfile();
using (var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST))
{
@@ -265,8 +301,20 @@ public class LoginManager : MonoBehaviour
PlayerPrefs.SetString(PlayerPrefsAuthKey, resp.token);
PlayerPrefs.Save();
yield return StartCoroutine(FetchUserDataCoroutine(null, true));
ProceedToMainMenu();
bool profileOk = false;
string profileErr = null;
yield return StartCoroutine(FetchUserDataCoroutine((success, err, _) =>
{
profileOk = success;
profileErr = err;
}, true));
if (profileOk)
ProceedToMainMenu();
else if (error_txt != null)
error_txt.text = string.IsNullOrEmpty(profileErr)
? "Signed in but could not load your profile. Check your connection and try again."
: profileErr;
}
else
{