https://firebase.google.com/docs/auth/unity/manage-users?hl=ko
I've been following this guide.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase.Auth;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Threading.Tasks;
public class CreatUser : MonoBehaviour {
private FirebaseAuth auth;
public InputField Email, Pass, UserName;
public Button SignUpButton, SignInButton, UpdateButton, CheckButton;
public Text ErrorText;
public string userName;
// // public Firebase.Auth.UserProfile profile;
// // Use this for initialization
void Start () {
auth = FirebaseAuth.DefaultInstance;
SignUpButton.onClick.AddListener(() => SignUp(Email.text, Pass.text));
SignInButton.onClick.AddListener(() => SingIn(Email.text, Pass.text));
UpdateButton.onClick.AddListener (() => SetUser (UserName.text));
CheckButton.onClick.AddListener (() => GetUser ());
DontDestroyOnLoad(this);
}
// // Update is called once per frame
void Update () {
}
public void SignUp(string email, string password){
if (string.IsNullOrEmpty (email) || string.IsNullOrEmpty (password)) {
Debug.Log ("Email or Password is Null");
}
else {
auth.CreateUserWithEmailAndPasswordAsync (email, password).ContinueWith (task => {
if (task.IsCanceled) {
Debug.LogError ("CreateUserWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError ("CreateUserWithEmailAndPasswordAsync error: " + task.Exception);
if (task.Exception.InnerExceptions.Count > 0)
UpdateErrorMessage (task.Exception.InnerExceptions [0].Message);
return;
}
FirebaseUser newUser = task.Result; // Firebase user has been created.
newUser.SendEmailVerificationAsync().ContinueWith(t =>
{
Debug.Log("SendEmailVerification");
UpdateErrorMessage("SendEmailVerificationAsync success");
});
Debug.Log("Email Send");
Debug.LogFormat ("Firebase User Created Successfully:{0}({1})",
newUser.DisplayName, newUser.UserId);
UpdateErrorMessage ("Sign Up Success");
});
}
}
private void UpdateErrorMessage(string message){
ErrorText.text = message;
Invoke ("ClearErrorMessage", 3);
}
void ClearErrorMessage(){
ErrorText.text = "";
}
public void SingIn(string email, string password){
UpdateErrorMessage ("Sign In Push");
auth.SignInWithEmailAndPasswordAsync (email, password).ContinueWith (task => {
if (task.IsCanceled) {
Debug.LogError ("SingInWithEmailAndPasswordAsync Canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError ("SingInWithEmailAndPasswordAsync error : " + task.Exception);
if (task.Exception.InnerExceptions.Count > 0)
UpdateErrorMessage (task.Exception.InnerExceptions [0].Message);
return;
}
FirebaseUser user = task.Result;
if(!user.IsEmailVerified){
UpdateErrorMessage("The email is not verified yet.");
auth.SignOut();
return;
}
UpdateErrorMessage ("User Signed In Successfully : " + user.UserId + user.ProviderId);
//Debug.LogFormat ("User Singed In Successfully: {0} ({1)}", // Login Successful
// // user.DisplayName, user.UserId);
});
}
private void SetUser(string name){
Firebase.Auth.FirebaseUser userFP = auth.CurrentUser;
if (userFP != null) {
Firebase.Auth.UserProfile profile;
profile.DisplayName = name;
profile.PhotoUrl = "";
userFP.UpdateUserProfileAsync (profile).ContinueWith (task => {
UpdateErrorMessage ("task");
if (task.IsCompleted) {
UpdateErrorMessage ("User Profile Updated");
}
});
}
}
public void GetUser(){
Firebase.Auth.FirebaseUser userFP = auth.CurrentUser;
userName = userFP.DisplayName;
UpdateErrorMessage ("username : " + userName);
// // SceneManager.LoadScene("Example");
}
}
The user profile update part was created as a SetUser function.
But you keep saying
Assets/Script/CreatUser.cs(108,4): error CS0165: Use of unassigned local variable `profile'
This error is displayed and cannot be executed. I followed the guide, but there was an error, so I don't know what to do.
I searched for the error and found that other people with the same error as me didn't initialize itWhat? It says to initialize the variable to null and try it.
So I added profile = null; and the error disappeared, but the function didn't work... What should I do at times like this?
firebase unity c#
Firebase.Auth.UserProfile profile;
profile.DisplayName = name;
profile.PhotoUrl = "";
This part
Firebase.Auth.UserProfile profile=new Firebase.Auth.UserProfile();
profile.DisplayName = name;
profile.PhotoUrl = "";
Try changing it like this. I am a problem because I access the member variable without 'profile' assigned.
However, even if profile = null; is added, it is normal if there is the same error, but if there is no error, it seems that the private void SetUser() function was not called at all.
593 Uncaught (inpromise) Error on Electron: An object could not be cloned
565 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
868 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
592 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.