Created
April 14, 2018 14:41
-
-
Save romreed/ccdf38d2859ba1213cb0e92d7a6619ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {NavigationActions} from 'react-navigation'; | |
import {AsyncStorage} from "react-native" | |
export const AUTH_REQUEST = 'AUTH_REQUEST' | |
export const auth = (code) => ({type: AUTH_REQUEST, payload: code}) | |
export const AUTH_SUCCESS = 'AUTH_SUCCESS' | |
export const authSuccess = (token) => ({type: AUTH_SUCCESS, payload: token}) | |
export const AUTH_ERROR = 'AUTH_ERROR' | |
export const authError = (error) => ({type: AUTH_ERROR, payload: error}) | |
export const CONFIRM_CODE_SUCCESS = 'CONFIRM_CODE_SUCCESS' | |
export const confirmCode = () => ({type: CONFIRM_CODE_SUCCESS,}) | |
export const CHECK_TOKEN = 'CHECK_TOKEN' | |
export const CHECK_TOKEN_SUCCESS = 'CHECK_TOKEN_SUCCESS' | |
export const CHECK_TOKEN_ERROR = 'CHECK_TOKEN_ERROR' | |
export const checkTnx = () => async (dispatch, getState) => { | |
dispatch({type:CHECK_TOKEN}) | |
try { | |
// console.log('AsyncStorage') | |
const value = AsyncStorage.getItem('tnx'); | |
// console.log('value',value) | |
if (value !== null){ | |
// We have data!! | |
// console.log("if",value ) | |
const resetAction = NavigationActions.reset({ | |
index: 0, | |
actions: [NavigationActions.navigate({routeName: 'Main'})], | |
}); | |
dispatch(resetAction); | |
// return dispatch({type:CHECK_TOKEN_SUCCESS, payload: response}) | |
return dispatch({type:CHECK_TOKEN_SUCCESS, payload: value}) | |
}else{ | |
// console.log('else') | |
return dispatch({type:CHECK_TOKEN_ERROR}) | |
} | |
} catch (error) { | |
// Error retrieving data | |
console.log("error",error) | |
} | |
} | |
export const USER_LOGOUT = 'USER_LOGOUT' | |
export const logOut = () => (dispatch, getState) => { | |
dispatch({type: USER_LOGOUT}) | |
AsyncStorage.clear() | |
const resetAction = NavigationActions.reset({ | |
index: 0, | |
actions: [NavigationActions.navigate({routeName: 'Registration'})], | |
}); | |
return dispatch(resetAction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment