diff --git a/README.md b/README.md index 0a5ce03..49b51db 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ And that's it! Your `SkateHub Frontend` should now be up and running locally on ### 2024 +- 2024-04-06 - Update the `signin` page of the SkateHub project [#14](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/14) _(v0.1.11)_ - 2024-04-03 - Create the `signup` page of the SkateHub project [#12](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/12) _(v0.1.10)_ - 2024-03-31 - Update `authentication` and `session` management [#11](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/11) _(v0.1.9)_ - 2024-03-29 - Create the `toast` component [#10](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/10) _(v0.1.8)_ diff --git a/package.json b/package.json index 82eaff6..ef653a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "0.1.10", + "version": "0.1.11", "private": true, "scripts": { "dev": "next dev", diff --git a/src/pages/auth/signin.tsx b/src/pages/auth/signin.tsx index a600bbd..7782019 100644 --- a/src/pages/auth/signin.tsx +++ b/src/pages/auth/signin.tsx @@ -1,9 +1,8 @@ import * as yup from "yup"; import { useContext } from "react"; -import { AxiosError } from "axios"; import { yupResolver } from "@hookform/resolvers/yup"; import { SubmitHandler, useForm } from "react-hook-form"; -import { Button, Flex, Stack, Text } from "@chakra-ui/react"; +import { Box, Button, Flex, Stack, Text } from "@chakra-ui/react"; import { Input } from "@/components/Form/Input"; import { Toast } from "@/components/Toast"; @@ -16,8 +15,8 @@ type SignInFormData = { }; const signInFormSchema = yup.object().shape({ - email: yup.string().required("E-mail obrigatório").email("E-mail inválido"), - password: yup.string().required("Password obrigatório") + email: yup.string().required("E-mail obrigatório.").email("E-mail inválido."), + password: yup.string().required("Password obrigatório.") }); export default function SignIn() { @@ -33,23 +32,42 @@ export default function SignIn() { const handleSignIn: SubmitHandler = async values => { await signIn(values) .then(_ => {}) - .catch((error: AxiosError) => { - console.error("error: ", error.message); - - addToast({ - title: "Erro de autenticação.", - message: "Verifique seus dados de login e tente novamente.", - type: "error" - }); + .catch(error => { + if (error.response?.data.error.message === "Your account email is not confirmed") { + addToast({ + title: "Erro de autenticação.", + message: "Confirme seu e-mail para acessar a plataforma.", + type: "warning" + }); + } else { + addToast({ + title: "Erro de autenticação.", + message: "Verifique seus dados de login e tente novamente.", + type: "error" + }); + } }); }; return ( - + + + + + Por favor, insira seu e-mail e senha cadastrado abaixo. Se precisar de ajuda, entre em{" "} + + contato conosco + + . + + + @@ -70,7 +99,7 @@ export default function SignIn() { - + Esqueci minha senha diff --git a/src/services/auth.ts b/src/services/auth.ts index b62144a..0918b59 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -1,6 +1,5 @@ import axios from "axios"; - -const strapiUrl = process.env.NEXT_PUBLIC_STRAPI_URL; +import { API } from "@/utils/constant"; type SignInData = { email: string; @@ -8,7 +7,7 @@ type SignInData = { }; export async function signInRequest({ email, password }: SignInData) { - const res = await axios.post(`${strapiUrl}/api/auth/local`, { + const res = await axios.post(`${API}/api/auth/local`, { identifier: email, password }); @@ -17,7 +16,7 @@ export async function signInRequest({ email, password }: SignInData) { } export async function userMe(token: string) { - const res = await axios.get(`${strapiUrl}/api/users/me`, { + const res = await axios.get(`${API}/api/users/me`, { headers: { Authorization: `Bearer ${token}` }