/
auth.js
34 lines (31 loc) · 899 Bytes
/
auth.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
// @flow
import { SIGN_OUT, tokenActions, refreshActions } from '../actions/auth';
import { getSuccessType, getFailureType } from '../utils/type-utils';
type actionType = {
+type: string
};
const initialState = {
accessToken: '',
idToken: '',
expiresIn: 0,
tokenType: '',
refreshToken: ''
};
export default function authReducer(state = initialState, action: actionType) {
switch (action.type) {
case getSuccessType(tokenActions):
case getSuccessType(refreshActions):
return {
accessToken: action.payload.access_token,
idToken: action.payload.id_token,
expiresIn: action.payload.expires_in,
tokenType: action.payload.token_type,
refreshToken: action.payload.refresh_token || state.refreshToken
};
case SIGN_OUT:
case getFailureType(refreshActions):
return initialState;
default:
return state;
}
}