SA_BLOG

Firebase 다른 아이디로 로그인하기 본문

프로그래밍/Android

Firebase 다른 아이디로 로그인하기

wooty9 2018. 3. 11. 17:53

지금까지 Firebase를 이용하여 구글 로그인 연동을 했을 때 한 번 로그인을 하면 다른 아이디로 로그인하지 못하는

문제가 있었는데 방법을 찾았다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    public void signOut() {
        if (mFirebaseAuth.getCurrentUser() != null) { // 로그인 상태가 아니면 (null 이면 로그인 상태가 아님)
            mFirebaseAuth.signOut(); // firebase 에서 로그아웃 하고
 
            Auth.GoogleSignInApi.signOut(mGoogleApiClient) // GoogleApi 에서 로그아웃 진행
                    .setResultCallback(new ResultCallback<Status>() { // 로그아웃 결과를 콜백
                        @Override
                        public void onResult(@NonNull Status status) {
                            if (status.isSuccess()) { // 로그아웃 성공이면
                                if (mFirebaseAuth.getCurrentUser() == null) { // 로그아웃 되었는지 한번 더 확인해서 로그아웃 상태이면
                                    ((Button) mActivity.findViewById(R.id.btnGoogleLogin)).setVisibility(View.VISIBLE); // 로그인, 로그아웃 버튼 Visible 속성 토글
                                    ((Button) mActivity.findViewById(R.id.btnGoogleLogout)).setVisibility(View.GONE);
 
                                    AlertDialog dialog = new AlertDialog.Builder(mActivity) // 로그아웃 된것을 알려주기 위해 다이얼로그 띄움
                                            .setTitle("알림")
                                            .setMessage("로그아웃 되었습니다.")
                                            .setPositiveButton("확인"null)
                                            .create();
 
                                    dialog.show();
                                }
                            }
                        }
                    });
        }
    }
cs


Comments