2020/02/02
login = () => {
const provider = new firebase.auth.FacebookAuthProvider();
// provider 부분만 변경한 후 진행하면 된다.
firebase
.auth()
.signInWithPopup(provider)
.then(res => {
console.log(res.credential.accessToken);
this.props.userInfo.userName = res.user.displayName;
console.log(res.user);
if (res) {
sessionStorage.setItem('accessToken', res.credential.accessToken);
this.moving();
}
})
.catch(error => {
alert('다시 로그인하세요' + error.message);
console.log(error);
});
};
import { observable } from 'mobx';
const LoginUserInfo = observable({
email: '',
password: '',
user: {
userName: '',
},
changeInfo(email, password) {
(this.email = email), (this.password = password);
},
welcome(text) {
this.user = {
userName: text,
};
},
});
export default LoginUserInfo;
import firebase from '../firebase';
import Router from 'next/router';
import LoginUserInfo from '../stores/loginStore/loginUser';
const moving = () => {
Router.push('/');
};
export const googleLogin = () => {
const provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then(res => {
if (res) {
LoginUserInfo.welcome(res.user.displayName);
sessionStorage.setItem('accessToken', res.credential.accessToken);
moving();
}
})
.catch(error => {
alert('다시 로그인하세요' + error.message);
console.log(error);
});
};
export const facebookLogin = () => {
const provider = new firebase.auth.FacebookAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then(res => {
if (res) {
LoginUserInfo.welcome(res.user.displayName);
sessionStorage.setItem('accessToken', res.credential.accessToken);
moving();
}
})
.catch(error => {
alert('다시 로그인하세요' + error.message);
console.log(error);
});
};
export const emailLogin = () => {
firebase
.auth()
.signInWithEmailAndPassword(LoginUserInfo.email, LoginUserInfo.password)
.then(res => {
if (res) {
LoginUserInfo.welcome(res.user.displayName);
// sessionStorage.setItem('accessToken', res.credential.accessToken)
moving();
}
})
.catch(error => {
alert('다시 로그인하세요');
console.log(error);
});
};
export const signup = () => {
firebase
.auth()
.createUserWithEmailAndPassword(LoginUserInfo.email, LoginUserInfo.password)
.then(res => {
console.log(res);
moving();
})
.catch(error => {
alert('다시 가입고고');
console.log(error);
});
};
export const logout = () => {
firebase.auth().signOut();
window.sessionStorage.clear();
LoginUserInfo.user.userName = '';
moving();
};