Browse Source

Login working on wpdAuth

master
analuizaff 3 years ago
parent
commit
d261e22486
  1. 10
      package-lock.json
  2. 19
      src/app/api/auth.js
  3. 7
      src/app/auth/authClient.js
  4. 13
      src/app/screens/LoginScreen.js

10
package-lock.json

@ -1,3 +1,11 @@
{
"lockfileVersion": 1
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"jwt-decode": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz",
"integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A=="
}
}
}

19
src/app/api/auth.js

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

7
src/app/auth/authClient.js

@ -0,0 +1,7 @@
import { create } from "apisauce";
const authClient = create({
baseURL: "http://191.233.193.200:8080/users",
});
export default authClient;

13
src/app/screens/LoginScreen.js

@ -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);

Loading…
Cancel
Save