개발/정보 / / 2022. 8. 31. 11:07

안드로이드 파이어베이스 익명 로그인 및 영구 계정 전환

반응형

 

1. 파이어베이스 프로젝트 익명 로그인 기능 추가

먼저 파이어베이스에 프로젝트를 생성하고 안드로이드 패키지와 연결합니다.

 

그후 파이어베이스 Authentication -> Sign-in method로 이동하여

새 제공업체를 선택하여 익명 사용 설정을 합니다.

파이어베이스 익명 로그인 설정

 

2. build.gradle (Module) 추가

dependencies {
	implementation 'com.google.firebase:firebase-auth'
}

 

 

3. 익명 로그인 기능 추가

- 익명 로그인 인스턴스를 생성합니다.

private FirebaseAuth mAuth;
        mAuth = FirebaseAuth.getInstance();

 

- 익명 로그인 호출

mAuth.signInAnonymously()
        .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    LogUtils.setLog(TAG, "Authentication success");
                    FirebaseUser user = mAuth.getCurrentUser();
                } else {
                    // If sign in fails, display a message to the user.
                    LogUtils.setLog(TAG, "Authentication failed");
                }
            }
        });

로그인에 성공하면 getCurrentUser 메서드로 사용자의 계정 정보를 가져올 수 있습니다.

 

 

# Android에서 익명으로 Firebase에 인증

파이어베이스 문서 및 익명 계정을 영구 계정으로 전환하는 방법

반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유