Last active
May 22, 2019 14:06
-
-
Save klosowsk/8da1e9240b54e7c364375692088af841 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 React, { useContext } from 'react'; | |
import { LoginContext } from "contexts/LoginContext"; | |
... | |
const signIn = async values => { | |
const loginContext = useContext(LoginContext); | |
try { | |
const { email, password } = values; | |
loginContext.actions.loginLoading(); | |
// Logs the user in... | |
const { token, ...userData } = await authenticate( | |
email, | |
password | |
); | |
// Sets the login user token in the local storage | |
await AsyncStorage.setItem('userToken', token); | |
// Updates the contexts related to the login | |
loginContext.actions.login(token); | |
} catch (error) { | |
// Logs the user out | |
loginContext.actions.logout(); | |
} | |
}; | |
export default signIn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment