Skip to content

Commit

Permalink
adding HandleRegister
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoAugusto31 committed Dec 24, 2023
1 parent 1409415 commit 543caba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/screens/Register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useContext, useState } from "react";
import Button from "../../components/Button";
import UserContext from "../../context/user";
import { useNavigation } from "@react-navigation/native";
import { Alert } from 'react-native';
import { register } from "../../services/auth";

export default function Register() {
const userData = useContext(UserContext);
Expand All @@ -12,8 +14,20 @@ export default function Register() {
userData.user?.token;
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const handleRegister = () => {};

const handleRegister = () => {

register({
username: username,
password: password,
})
.then(function (response) {
Alert.alert("Success", "Registro bem-sucedido. Faça login para continuar.");
})
.catch(function (error) {
console.error("error", error);
Alert.alert("Error", "Erro ao registrar. Verifique suas informações.");
});
};
return (
<Flex p={5} flex={1} justifyContent="center" alignItems="center">
<Heading>Tela cadastro</Heading>
Expand Down
3 changes: 2 additions & 1 deletion src/services/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import api from ".";

export const login = (loginData: any) => api.post("/user/login", loginData);
export const login = (loginData: any) => api.post("/user/login", loginData);
export const register = (loginData: any) => api.post("/user/register", loginData);

0 comments on commit 543caba

Please sign in to comment.