73 lines
1.3 KiB
JavaScript
73 lines
1.3 KiB
JavaScript
import firebase from 'firebase';
|
|
import { firebaseAuth } from '../firebase';
|
|
import {
|
|
INIT_AUTH,
|
|
SIGN_IN_ERROR,
|
|
SIGN_IN_SUCCESS,
|
|
SIGN_OUT_SUCCESS
|
|
} from './action-types';
|
|
|
|
|
|
function authenticate(provider) {
|
|
return dispatch => {
|
|
//cc:signin#1;firebase sign in;+1;call to firebase with auth provider, proceed if success response
|
|
firebaseAuth.signInWithPopup(provider)
|
|
.then(result => dispatch(signInSuccess(result)))
|
|
.catch(error => dispatch(signInError(error)));
|
|
};
|
|
}
|
|
|
|
|
|
export function initAuth(user) {
|
|
return {
|
|
type: INIT_AUTH,
|
|
payload: user
|
|
};
|
|
}
|
|
|
|
|
|
export function signInError(error) {
|
|
return {
|
|
type: SIGN_IN_ERROR,
|
|
payload: error
|
|
};
|
|
}
|
|
|
|
|
|
export function signInSuccess(result) {
|
|
return {
|
|
type: SIGN_IN_SUCCESS,
|
|
payload: result.user
|
|
};
|
|
}
|
|
|
|
|
|
export function signInWithGithub() {
|
|
return authenticate(new firebase.auth.GithubAuthProvider());
|
|
}
|
|
|
|
|
|
export function signInWithGoogle() {
|
|
return authenticate(new firebase.auth.GoogleAuthProvider());
|
|
}
|
|
|
|
|
|
export function signInWithTwitter() {
|
|
return authenticate(new firebase.auth.TwitterAuthProvider());
|
|
}
|
|
|
|
|
|
export function signOut() {
|
|
return dispatch => {
|
|
firebaseAuth.signOut()
|
|
.then(() => dispatch(signOutSuccess()));
|
|
};
|
|
}
|
|
|
|
|
|
export function signOutSuccess() {
|
|
return {
|
|
type: SIGN_OUT_SUCCESS
|
|
};
|
|
}
|