안녕하세요~
아래 스크립트를 만들어서 유니티에서 Play를 시키자마자
아래와 같은 에러가 뜹니다.
회원가입을 하려고 들어간 건데
로그인이 안되어 있다고???
무슨 말인지 모르겠어요…
(에러메세지)
Exception in AutoLogin: The client not login yet. Please login first (0)
System.ArgumentNullException: Value cannot be null.
Parameter name: origin data
at hl4J5uO5EVqr2t3FGVS.nrsP7FOEBDnSLa5TX2g.E7tOSyavU8 (System.Byte[] ) [0x00007] in :0
(스크립트)
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using BackEnd;
public class LoginManager : MonoBehaviour
{
[SerializeField] private TMP_InputField userIdInputField;
[SerializeField] private TMP_InputField passwordInputField;
[SerializeField] private TMP_InputField emailInputField;
[SerializeField] private TextMeshProUGUI resultText;
[SerializeField] private Button idPasswordFindButton;
[SerializeField] private Button submitButton;
[SerializeField] private Button startButton;
private bool isProcessing = false;
void Start()
{
if (userIdInputField == null) Debug.LogError("UserIdInputField is not assigned.");
if (passwordInputField == null) Debug.LogError("PasswordInputField is not assigned.");
if (emailInputField == null) Debug.LogError("EmailInputField is not assigned.");
if (resultText == null) Debug.LogError("ResultText is not assigned.");
if (idPasswordFindButton == null) Debug.LogError("IDPasswordFindButton is not assigned.");
if (submitButton == null) Debug.LogError("SubmitButton is not assigned.");
if (startButton == null) Debug.LogError("StartButton is not assigned.");
submitButton.onClick.AddListener(OnSubmitButtonClicked);
idPasswordFindButton.onClick.AddListener(OnIDPasswordFindButtonClicked);
startButton.interactable = false; // 초기에는 비활성화
AutoLogin();
}
public void OnSubmitButtonClicked()
{
if (isProcessing) return;
string userId = userIdInputField.text;
string password = passwordInputField.text;
string email = emailInputField.text;
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
{
resultText.text = "Please enter User ID, Password, and Email.";
Debug.Log("User ID, Password, or Email is empty.");
return;
}
isProcessing = true;
RegisterAndLogin(userId, password, email);
}
public void OnIDPasswordFindButtonClicked()
{
if (isProcessing) return;
string userId = userIdInputField.text;
string email = emailInputField.text;
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(email))
{
resultText.text = "Please enter both User ID and Email.";
Debug.Log("User ID or Email is empty.");
return;
}
isProcessing = true;
RequestPasswordReset(userId, email);
}
private void AutoLogin()
{
try
{
BackendReturnObject tokenCheck = Backend.BMember.IsAccessTokenAlive();
if (tokenCheck.IsSuccess())
{
Debug.Log("Token is alive. Attempting auto login.");
Backend.BMember.LoginWithTheBackendToken(callback =>
{
try
{
if (callback.IsSuccess())
{
Debug.Log("Auto Login Successful: " + callback);
ShowWelcomeMessage();
startButton.interactable = true; // 자동 로그인 성공 시 스타트 버튼 활성화
}
else
{
Debug.LogError("Auto Login Failed: " + callback);
if (resultText != null)
resultText.text = $"Auto Login Failed: {callback.GetErrorCode()} - {callback.GetMessage()}";
}
}
catch (System.Exception ex)
{
Debug.LogError("Exception in AutoLogin Callback: " + ex.Message);
}
});
}
else
{
Debug.Log("No valid token found. Please log in.");
if (resultText != null) resultText.text = "No valid token found. Please log in.";
}
}
catch (System.Exception ex)
{
Debug.LogError("Exception in AutoLogin: " + ex.Message);
}
}
private void RegisterAndLogin(string userId, string password, string email)
{
Debug.Log($"Attempting to sign up with UserID: {userId}, Password: {password}, Email: {email}");
Backend.BMember.CustomSignUp(userId, password, email, callback =>
{
Debug.Log("Sign up callback received.");
isProcessing = false;
try
{
if (callback.IsSuccess())
{
Debug.Log("Sign Up Successful: " + callback);
if (resultText != null) resultText.text = "Sign Up Successful";
CustomLogin(userId, password); // 회원가입 후 자동 로그인 시도
}
else
{
Debug.LogError("Sign Up Failed: " + callback);
if (resultText != null) resultText.text = $"Sign Up Failed: {callback.GetErrorCode()} - {callback.GetMessage()}";
}
}
catch (System.Exception ex)
{
Debug.LogError("Exception in SignUp Callback: " + ex.Message);
}
});
}
private void CustomLogin(string userId, string password)
{
Debug.Log($"Attempting to login with UserID: {userId}, Password: {password}");
Backend.BMember.CustomLogin(userId, password, callback =>
{
Debug.Log("Login callback received.");
isProcessing = false;
try
{
if (callback.IsSuccess())
{
Debug.Log("Login Successful: " + callback);
if (resultText != null) resultText.text = "Login Successful";
ShowWelcomeMessage(); // 로그인 성공 시 환영 메시지 표시
startButton.interactable = true; // 로그인 성공 시 스타트 버튼 활성화
}
else
{
Debug.LogError("Login Failed: " + callback);
if (resultText != null) resultText.text = $"Login Failed: {callback.GetErrorCode()} - {callback.GetMessage()}";
}
}
catch (System.Exception ex)
{
Debug.LogError("Exception in Login Callback: " + ex.Message);
}
});
}
private void RequestPasswordReset(string userId, string email)
{
Debug.Log($"Attempting to reset password for UserID: {userId}, Email: {email}");
Backend.BMember.ResetPassword(userId, email, callback =>
{
Debug.Log("Password reset callback received.");
isProcessing = false;
try
{
if (callback.IsSuccess())
{
Debug.Log("Password reset email sent successfully: " + callback);
if (resultText != null) resultText.text = "Password reset email sent.";
}
else
{
Debug.LogError("Failed to send password reset email: " + callback);
if (resultText != null) resultText.text = $"Failed to send password reset email: {callback.GetMessage()}";
}
}
catch (System.Exception ex)
{
Debug.LogError("Exception in Password Reset Callback: " + ex.Message);
}
});
}
private void ShowWelcomeMessage()
{
Debug.Log("Welcome to the game!");
// 환영 메시지를 표시하는 로직 추가
}
}