Skip to content

Instantly share code, notes, and snippets.

@cionman
Last active December 2, 2017 13:09
Show Gist options
  • Save cionman/e2abc66734a14c93eb6fd0ae5957aed6 to your computer and use it in GitHub Desktop.
Save cionman/e2abc66734a14c93eb6fd0ae5957aed6 to your computer and use it in GitHub Desktop.
구글계정으로 가입 및 로그인 작성
<script>
/**
* FirebaseChat ES5 클래스
*/
function FirebaseChat(){
this.init();
this.initEvent();
}
/**
* 초기 필드 변수 할당
*/
FirebaseChat.prototype.init = function(){
this.auth = firebase.auth();
this.liGoogleBtn = document.getElementById('liGoogleBtn');
}
/**
* 초기 이벤트 바인딩
*/
FirebaseChat.prototype.initEvent = function(){
this.liGoogleBtn.addEventListener('click', this.onGoogleBtnClick.bind(this));
this.auth.onAuthStateChanged(this.onAuthChange.bind(this));
}
/**
* Google 로그인 버튼 클릭
*/
FirebaseChat.prototype.onGoogleBtnClick = function(){
var googleProvider = new firebase.auth.GoogleAuthProvider();
this.auth.signInWithPopup(googleProvider).then(function(result) {
console.log('로그인 성공')
}).catch(function(error) {
alert('로그인에 실패하였습니다');
console.error('구글 로그인 과정 에러',error);
});
}
/**
* 인증 정보가 변화 되었을 시에 변화
*/
FirebaseChat.prototype.onAuthChange = function(user){
if (user) {
console.log('user로그인 : ',JSON.stringify(user));
} else {
console.log('로그아웃')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment