-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcurrentUser.js
More file actions
77 lines (68 loc) · 2.06 KB
/
Copy pathcurrentUser.js
File metadata and controls
77 lines (68 loc) · 2.06 KB
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
75
76
77
import {createConstants, createReducer} from 'redux-module-builder'
export const types = createConstants('currentUser')(
'INITIALIZED',
'SIGNED_IN',
'SIGNED_OUT'
)
export const actions = {
init: (cfg) => (dispatch, getState) => {
const {server, authManager} = getState();
const intitialize = () => {
server.listenForAuth((evt) => {
if (!evt.authenticated) {
dispatch(actions.userSignedOut(evt.error));
} else {
dispatch(actions.userSignedIn(evt.user))
}
})
authManager.configureProvider("twitter", {
consumer_key: 'EFSw5Wx703eTjzAKCMwMdp0Vf',
consumer_secret: 'RPm1CMAjHDrMaYodmr1jP2AYXCCEl4on03bqmQP0Udm809f3Sg'
})
}
// Regardless of the success/failure, initialize the app
server.configure(cfg)
.then(intitialize)
.catch(intitialize)
server.on('debug', (msg) => console.log('DEBUG:', msg));
},
userSignedIn: (user) => ({type: types.SIGNED_IN, payload: user}),
userSignedOut: (err) => ({type: types.SIGNED_OUT, payload: err}),
signUpWith: (provider) => (dispatch, getState) => {
const {server, authManager} = getState();
const appUrl = `sticker-me://oauth-callback/${provider}`
authManager.authorizeWithCallbackURL(provider, appUrl)
.then((creds) => {
server
.signInWithProvider(provider,
creds.oauth_token,
creds.oauth_token_secret)
.then((user) => {
// We're now signed in through Firebase
dispatch({type: types.SIGNED_IN, payload: user});
})
.catch(err => {
// There was an error
dispatch({type: types.SIGNED_OUT, payload: err});
})
})
.catch((err) => {
console.log('error ->', err)
})
}
}
export const reducer = createReducer({
[types.SIGNED_IN]: (state, {payload}) => ({
...state,
loggedIn: true,
user: payload
}),
[types.SIGNED_OUT]: (state, {payload}) => ({
...state,
loggedIn: false,
user: null
})
});
export const initialState = {
user: null
}