Browse Source

going back to initial loging due to api instability

master
analuizaff 3 years ago
parent
commit
d81b32f382
  1. 19
      src/app/api/auth.js
  2. 11
      src/app/screens/LoginScreen.js

19
src/app/api/auth.js

@ -1,7 +1,20 @@
import { create } from "apisauce"; import { create } from "apisauce";
import authClient from "../auth/authClient"; import authClient from "../auth/authClient";
const login = (name, password) =>
authClient.post(`/login?username=${name}&password=${password}`);
/*const login = (name, password) =>
authClient.post(`/login?username=${name}&password=${password}`);*/
function login(name, password) {
// NOTE: Change to API in future
if (name !== "1199998888" || password !== "qwertyui") {
return {
ok: false,
};
}
return {
ok: true,
data:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVXN1w6FyaW8gVGVzdGUiLCJlbWFpbCI6InVzdWFyaW9AdGVzdGUuY29tLmJyIiwiaW5zdGl0dXRpb25OYW1lIjoiRS4gRS4gVmljZW50ZSBMZXBvcmFjZSIsImluc3RpdHV0aW9uVHlwZSI6IkVzY29sYSIsIklEIjoiMSJ9.dk-Nl5VLvAWhT_JUYREpJYYCc98s71SyHJwmwH55ZS4",
};
}
export default { login };
export default login;

11
src/app/screens/LoginScreen.js

@ -17,7 +17,8 @@ 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";
const phoneRegex = RegExp( const phoneRegex = RegExp(
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/ /^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/
@ -25,11 +26,11 @@ const phoneRegex = RegExp(
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
name: Yup.string() name: Yup.string()
.matches(/[a-zA-Z]/, "Número inválido")
.matches(phoneRegex, "Número inválido")
.required("O número de telefone é obrigatório"), .required("O número de telefone é obrigatório"),
password: Yup.string() password: Yup.string()
.required("A senha é obrigatória") .required("A senha é obrigatória")
.min(5, "Senha muito curta, minimo 8 caracteres")
.min(8, "Senha muito curta, minimo 8 caracteres")
.matches(/[a-zA-Z]/, "A senha só pode conter letras"), .matches(/[a-zA-Z]/, "A senha só pode conter letras"),
}); });
@ -77,8 +78,8 @@ 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 = await authApi.login(name, password);
// console.log(result.ok);
const result = login(name, password);//await authApi.login(name, password);
console.log(JSON.stringify(result));
if (!result.ok) return setLoginFailed(true); if (!result.ok) return setLoginFailed(true);
setLoginFailed(false); setLoginFailed(false);

Loading…
Cancel
Save