Last active
July 26, 2017 15:20
-
-
Save iRoachie/7b6d5f33d9c9c8385f6f47822e7cea2f to your computer and use it in GitHub Desktop.
Login Thunk
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
export function login(email: string, password: string) { | |
return async (dispatch: Dispatch<Store>) => { | |
dispatch({ type: LOGIN_START }) | |
try { | |
const loginResponse = await Api.post('applogin', { | |
email, | |
password, | |
app_name: DeviceInfo.getModel(), | |
}) | |
if (loginResponse.error) { | |
dispatch({ type: LOGIN_FAILED, payload: loginResponse.error }) | |
} else { | |
const advertiserResponse = await Api.get( | |
'advertisers.json', | |
loginResponse.key | |
) | |
dispatch({ type: LOGIN_SUCCEEDED, payload: loginResponse.key }) | |
} | |
} catch (err) { | |
dispatch({ type: LOGIN_FAILED, payload: 'Error logging in' }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment