-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathactions.js
74 lines (56 loc) · 1.32 KB
/
actions.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
};
}