|
|
@ -10,13 +10,14 @@ import { |
|
|
|
import Screen from "../components/Screen"; |
|
|
|
import colors from "../config/colors"; |
|
|
|
import { dimensions } from "../config/dimensions"; |
|
|
|
import login from "../api/auth"; |
|
|
|
|
|
|
|
import jwdDecode from "jwt-decode"; |
|
|
|
import { AuthContext } from "../auth/context"; |
|
|
|
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'; |
|
|
|
|
|
|
|
const phoneRegex = RegExp( |
|
|
|
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/ |
|
|
@ -24,11 +25,11 @@ const phoneRegex = RegExp( |
|
|
|
|
|
|
|
const validationSchema = Yup.object().shape({ |
|
|
|
name: Yup.string() |
|
|
|
.matches(phoneRegex, "Número inválido") |
|
|
|
.matches(/[a-zA-Z]/, "Número inválido") |
|
|
|
.required("O número de telefone é obrigatório"), |
|
|
|
password: Yup.string() |
|
|
|
.required("A senha é obrigatória") |
|
|
|
.min(8, "Senha muito curta, minimo 8 caracteres") |
|
|
|
.min(5, "Senha muito curta, minimo 8 caracteres") |
|
|
|
.matches(/[a-zA-Z]/, "A senha só pode conter letras"), |
|
|
|
}); |
|
|
|
|
|
|
@ -75,9 +76,9 @@ function DashedOrSeparator() { |
|
|
|
export default function LoginScreen(props) { |
|
|
|
const authContext = useContext(AuthContext); |
|
|
|
|
|
|
|
const handleSubmit = (name, password, setLoginFailed) => { |
|
|
|
const result = login(name, password); |
|
|
|
console.log(result); |
|
|
|
const handleSubmit = async (name, password, setLoginFailed) => { |
|
|
|
const result = await authApi.login(name, password); |
|
|
|
console.log(result.ok); |
|
|
|
if (!result.ok) return setLoginFailed(true); |
|
|
|
|
|
|
|
setLoginFailed(false); |
|
|
|