개발일지
unity -> cloud once + playfab login 구현 오류 unity GetServerAuthCode null
go_ra_ni
2023. 5. 12. 16:38
728x90
상황 :
기존 앱에 cloud once로 로그인 기능을 구현해 둔 상태였고 playfab 서버를 추가하는 상황이다.
playfab 공식문서에 의하면 이러한 과정을 통해 로그인을 구현한다고 한다.
하지만 이대로 진행하면 GetServerAuthCode가 null 인 문제가 발생한다.
나의 경우 문제는 cloud once와 충돌로 로그인이 2번 진행됐기때문에 발생한 문제였다.
해결:
1. cloud once 자동 로그인을 끄고 직접 코드를 짠다.
2. cloud once 자동 로그인이 진행되는 코드를 수정하여 해결한다.
현재 google과 ios 모두 자동로그인을 사용하고 있었는데 google에서만 이슈가 발생했다.
새롭게 두 플랫폼의 로그인을 구현하는 것보단 기존 로그인 코드에 playfab을 연동하는 것이 더 좋다고 판단하여 2번 방법을 채택했다.
로그인 코드는 google -> GooglePlayGamesCloudProvider.cs 파일에 있다.
public override void SignIn(bool autoCloudLoad = true, UnityAction<bool> callback = null)
{
if (!IsGpgsInitialized)
{
Debug.LogWarning("SignIn called, but Google Play Game Services has not been initialized. Ignoring call.");
CloudOnceUtils.SafeInvoke(callback, false);
return;
}
autoLoadEnabled = autoCloudLoad;
IsGuestUserDefault = false;
Logger.d("Attempting to sign in to Google Play Game Services.");
PlayGamesPlatform.Instance.Authenticate(success =>
{
// Success is handled by OnAuthenticated method
if (!success)
{
Logger.w("Failed to sign in to Google Play Game Services.");
bool hasNoInternet;
try
{
hasNoInternet = InternetConnectionUtils.GetConnectionStatus() != InternetConnectionStatus.Connected;
}
catch (NotSupportedException)
{
hasNoInternet = Application.internetReachability == NetworkReachability.NotReachable;
}
if (hasNoInternet)
{
Logger.d("Failure seems to be due to lack of Internet. Will try to connect again next time.");
}
else
{
Logger.d("Must assume the failure is due to player opting out"
+ " of the sign-in process, setting guest user as default");
IsGuestUserDefault = true;
}
cloudOnceEvents.RaiseOnSignInFailed();
if (autoCloudLoad)
{
cloudOnceEvents.RaiseOnCloudLoadComplete(false);
}
}
print("cloud once auto login -> playfab login");
var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
print(serverAuthCode);
var request = new PlayFab.ClientModels.LoginWithGoogleAccountRequest
{
TitleId = PlayFabSettings.TitleId,
ServerAuthCode = serverAuthCode,
CreateAccount = true
};
print("request info");
print(request.TitleId);
print(request.ServerAuthCode);
PlayFabClientAPI.LoginWithGoogleAccount(request, (result) =>
{
print("Signed In as " + result.PlayFabId);
PlayFabManager.instance.OnLogin(result);
}, OnSharedFailure);
CloudOnceUtils.SafeInvoke(callback, success);
});
}
아랫 부분에 Playfab api를 추가하면 작동한다. (playfabManager를 싱글톤으로 만들었기에 작동했다. )
테스트 후 별 문제는 없었지만 ios의 경우 로그인을 2번 진행해도 잘 돌아간다는 문제가 있었다.
추후 수정 예정..
728x90