728x90
이번엔, firebase를 활용해 로그인과 회원가입을 구현해보자.
firebase는 다양한 함수와 기능을 제공한다.
이번엔 Firebase.Auth를 사용하여 진행할것이다.
일단, Firebase에 접속하여 회원가입 기능을 활성화하자.
여기로 들어가서
로그인 방법에서 새 공급업체를 추가하면 된다.
나는 이미 추가해서 이렇게 뜨지만, 시작하기를 누르면 어떤 로그인 방법을 지원할것인지 물어볼것이다.
여기서 이메일/비밀번호를 누르고,
위의 항목을 사용설정해주자.
그리고 저장을 하고 빠져나오자.
유니티에선 다음과 같이 로그인 UI를 구현했다.
버튼, InputField 모두 TMP를 사용하여 구현했다. 기본적인 button, inputField를 사용해도 무방하다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase.Auth;
using UnityEngine.UI;
using UnityEditor;
using TMPro;
public class SignManager : MonoBehaviour
{
[SerializeField] TMP_InputField idInput;
[SerializeField] TMP_InputField pwInput;
Firebase.Auth.FirebaseAuth auth;
private void Awake() {
//객체 초기화
auth = FirebaseAuth.DefaultInstance;
}
public void Login(){
auth.SignInWithEmailAndPasswordAsync(idInput.text, pwInput.text).ContinueWith(
task => {
if(task.IsCompleted && !task.IsFaulted && !task.IsCanceled){
Debug.Log($"{idInput.text} 로 로그인 성공");
} else{
Debug.Log($"로그인 실패");
}
}
);
}
public void Register(){
auth.CreateUserWithEmailAndPasswordAsync(idInput.text, pwInput.text).ContinueWith(
task => {
if(!task.IsCanceled && !task.IsFaulted){
Debug.Log($"{idInput.text}로 회원가입");
}else{
Debug.Log($"회원가입 실패");
}
}
);
}
}
이 코드를 작성하여 로그인, 회원가입 버튼에 각각 붙이고, 알맞은 함수를 등록하자.
따로 로그인 후 기능은 안만들었지만, 이렇게 하면 로그인이 완료된다.
회원가입이 잘 되는것을 볼 수 있다.
앞으로 구현할때, 로그인 후 다른 씬으로 넘어가는 식의 코드를 짜면 될것같다.
728x90
'Develop > Firebase' 카테고리의 다른 글
[Firebase] Firebase를 이용한 서버 구현 (FireBase) - 3. 파일 입출력 (0) | 2024.06.14 |
---|---|
[Firebase] Firebase를 이용한 서버 구현 (FireBase) - 2. 시작 스크립트 작성 (0) | 2024.06.13 |
[Firebase] Firebase를 이용한 서버 구현 (FireBase) - 1. FireBase가입 (0) | 2024.06.13 |