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