Skip to content

Commit

Permalink
Merge pull request #31 from GED-Extensao-ADS-4/user-login
Browse files Browse the repository at this point in the history
User login
  • Loading branch information
lucas0headshot authored Dec 13, 2024
2 parents 2e6706c + 106273d commit a786842
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import { ChangeEvent, FormEvent, ReactElement, useState } from "react";
import { Button, CardLink, Col, Container, Form, Image, Row } from "react-bootstrap";
import { login } from "../services/auth";
import { useNavigate } from "react-router-dom";
import axios from "axios";

/**
* @description Página de login.
* @author Lucas Ronchi <@lucas0headshot>
* @since 25/11/2024
*/

interface User {
username: string,
password: string
}

interface Response {
token: string
}


const Login = (): ReactElement => {
const [email, setEmail] = useState<string>("");
const [senha, setSenha] = useState<string>("");
Expand All @@ -21,13 +33,24 @@ const Login = (): ReactElement => {
setSenha(event.target.value);
}

const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
console.info("Email:", email);
console.info("Senha:", senha);

const user: User = {
username: email,
password: senha
}

const response = await axios.post<Response>('http://localhost:8080/user/login', user)

console.log(response.data);

const { token } = response.data;

//!Realocar lógica
login(email + senha);
login(token);

alert("Logado com sucesso!");
navigate("/");
Expand Down

0 comments on commit a786842

Please sign in to comment.