Skip to content

Commit

Permalink
add clientID
Browse files Browse the repository at this point in the history
  • Loading branch information
kaihirota committed Oct 20, 2024
1 parent 2e46883 commit 1d9c501
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions Assets/Shared/Scripts/UI/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Immutable.Passport;

namespace HyperCasual.Runner
{
Expand All @@ -23,7 +24,9 @@ public class MainMenu : View
[SerializeField]
GameObject m_Loading;

void OnEnable()
Passport passport;

async void OnEnable()
{
ShowLoading(true);

Expand All @@ -34,8 +37,41 @@ void OnEnable()
m_LogoutButton.RemoveListener(OnLogoutButtonClick);
m_LogoutButton.AddListener(OnLogoutButtonClick);

// Initialise Passport
string clientId = "Jf3dcKYrYUC6MLCMsDsOvKGoirlAzGJR";
string environment = Immutable.Passport.Model.Environment.SANDBOX;
string redirectUri = null;
string logoutUri = null;

#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
redirectUri = "immutablerunner://callback";
logoutUri = "immutablerunner://logout";
#endif
passport = await Passport.Init(clientId, environment, redirectUri, logoutUri);

// Check if the player is supposed to be logged in and if there are credentials saved
if (SaveManager.Instance.IsLoggedIn && await Passport.Instance.HasCredentialsSaved())
{
// Try to log in using saved credentials
bool success = await Passport.Instance.Login(useCachedSession: true);
// Update the login flag
SaveManager.Instance.IsLoggedIn = success;
// Set up wallet if successful
if (success)
{
await Passport.Instance.ConnectEvm();
await Passport.Instance.ZkEvmRequestAccounts();
}
}
else
{
// No saved credentials to re-login the player, reset the login flag
SaveManager.Instance.IsLoggedIn = false;
}

ShowLoading(false);
ShowStartButton(true);
// Show the logout button if the player is logged in
ShowLogoutButton(SaveManager.Instance.IsLoggedIn);
}

void OnDisable()
Expand All @@ -49,7 +85,7 @@ void OnStartButtonClick()
AudioManager.Instance.PlayEffect(SoundID.ButtonSound);
}

void OnLogoutButtonClick()
async void OnLogoutButtonClick()
{
try
{
Expand All @@ -59,6 +95,11 @@ void OnLogoutButtonClick()
ShowLoading(true);

// Logout
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
await passport.LogoutPKCE();
#else
await passport.Logout();
#endif

// Reset the login flag
SaveManager.Instance.IsLoggedIn = false;
Expand Down

0 comments on commit 1d9c501

Please sign in to comment.