コード例 #1
0
    /// <summary>
    /// Ukoliko zelimo da apdejtujemo email za nekog korisnika, treba to uraditi koriscenjem ove funkcije
    /// </summary>
    public void UpdateUsersEmail(string email)
    {
        Firebase.Auth.FirebaseUser user = auth.CurrentUser;
        if (user != null)
        {
            user.UpdateEmailAsync(email).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("UpdateEmailAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("UpdateEmailAsync encountered an error: " + task.Exception);
                    return;
                }

                Debug.Log("User email updated successfully.");
            });
        }
    }
コード例 #2
0
    public void OnSignIn()
    {
        Debug.Log($"Try Sign in");
        GoogleSignIn.Configuration = configuration;
        GoogleSignIn.Configuration.UseGameSignIn  = false;
        GoogleSignIn.Configuration.RequestIdToken = true;
        AddStatusText("Calling SignIn");

        Task <GoogleSignInUser> signIn = GoogleSignIn.DefaultInstance.SignIn();

        TaskCompletionSource <FirebaseUser> signInCompleted = new TaskCompletionSource <FirebaseUser>();

        signIn.ContinueWith(task =>
        {
            Debug.Log($"Start ");
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                signInCompleted.SetCanceled();
            }
            else if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                signInCompleted.SetException(task.Exception);
            }
            else
            {
                Debug.Log($"Token : {((Task<GoogleSignInUser>)task).Result.IdToken}");
                Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
                Credential credential           = Firebase.Auth.GoogleAuthProvider.GetCredential(((Task <GoogleSignInUser>)task).Result.IdToken, null);
                auth.SignInWithCredentialAsync(credential).ContinueWith(authTask => {
                    Debug.Log($"{authTask.Status}");
                    if (authTask.IsCanceled)
                    {
                        Debug.Log($"canceled");
                        signInCompleted.SetCanceled();
                    }
                    else if (authTask.IsFaulted)
                    {
                        Debug.Log($"{authTask.Exception}");
                        signInCompleted.SetException(authTask.Exception);
                    }
                    else
                    {
                        signInCompleted.SetResult(((Task <FirebaseUser>)authTask).Result);
                        Debug.Log($"Mail : {auth.CurrentUser.Email}");
                        Debug.Log($"{((Task<GoogleSignInUser>)task).Result.Email}");

                        Debug.Log($"Mail : {auth.CurrentUser.Email}");
                        AddStatusText("Welcome: " + task.Result.DisplayName + "!");
                        Firebase.Auth.FirebaseUser newUser = authTask.Result;

                        newUser.UpdateEmailAsync(((Task <GoogleSignInUser>)task).Result.Email).ContinueWith((d) => { Debug.Log($"{newUser.Email}"); }).Start();

                        Debug.LogFormat("User signed in successfully: {0} ({1})",
                                        newUser.DisplayName, newUser.UserId);
                        FirebaseDatabase.DefaultInstance.RootReference.Child($"{auth.CurrentUser.DisplayName}/").SetRawJsonValueAsync("");
                    }
                });
            }
        });
    }