Browse Source

API connection in LoginScreen

master
GabrielTrettel 3 years ago
parent
commit
84f1a1ea7b
  1. 7
      src/app/screens/LoginScreen.js

7
src/app/screens/LoginScreen.js

@ -17,7 +17,7 @@ import authStorage from "../auth/storage";
import assets from "../config/assets";
import Button from "../components/Button";
import { TouchableNativeFeedback } from "react-native-gesture-handler";
//import authApi from '../api/auth';
// import authApi from '../api/auth';
import login from "../api/auth";
const phoneRegex = RegExp(
@ -78,14 +78,15 @@ export default function LoginScreen(props) {
const authContext = useContext(AuthContext);
const handleSubmit = async (name, password, setLoginFailed) => {
const result = login(name, password);//await authApi.login(name, password);
const result = await login(name, password);
console.log(JSON.stringify(result));
if (!result.ok) return setLoginFailed(true);
setLoginFailed(false);
const user = jwdDecode(result.data);
authContext.setUser(user);
console.log(user);
console.log("usuário: " + JSON.sstringify(user));
authStorage.setToken(result.data);
};

Loading…
Cancel
Save