Skip to content

Instantly share code, notes, and snippets.

@klosowsk
Last active May 22, 2019 14:06
Show Gist options
  • Save klosowsk/8da1e9240b54e7c364375692088af841 to your computer and use it in GitHub Desktop.
Save klosowsk/8da1e9240b54e7c364375692088af841 to your computer and use it in GitHub Desktop.
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