2020/02/01
npm install firebase
import firebase from 'firebase';
const config = {
apiKey: '비~밀~',
authDomain: '비~밀~',
databaseURL: '비~밀~',
projectId: '비~밀~',
storageBucket: '비~밀~',
messagingSenderId: '비~밀~',
appId: '비~밀~',
measurementId: '비~밀~',
};
try {
firebase.app();
} catch (error) {
firebase.initializeApp(config);
}
export default firebase;
import firebase from 'firebase';
import config from './config/firebase';
try {
firebase.app();
} catch (error) {
firebase.initializeApp(config);
}
export default firebase;
login = () => {
const provider = new firebase.auth.GoogleAuthProvider();
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);
});
};
emailLogin = () => {
firebase
.auth()
.signInWithEmailAndPassword(this.state.id, this.state.password)
.then(res => {
console.log(res.credential);
console.log(res.user);
if (res) {
// sessionStorage.setItem("refreshToken", res.credential.refreshToken);
this.props.userInfo.userName = res.user.email;
this.moving();
}
})
.catch(error => {
alert('다시 로그인하세요');
console.log(error);
});
};
signup = () => {
firebase
.auth()
.createUserWithEmailAndPassword(this.state.id, this.state.password)
.then(res => {
console.log(res);
this.setState({
id: '',
password: '',
});
})
.catch(error => {
console.log(error);
});
};