apply suggestions
continuous-integration/drone/push Build is passing Details

pull/107/head
maxime 1 year ago
parent 221100e842
commit 0a451334d2

@ -1,22 +0,0 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "react", "react-hooks"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
],
rules: {
"prefer-const": ["error", {
"destructuring": "all"
}]
},
settings: {
react: {
version: "detect",
},
},
}

@ -1,3 +1,8 @@
# THIS FILE IS DEPRECATED
See [#107](https://codefirst.iut.uca.fr/git/IQBall/Application-Web/pulls/107) for more details
-----
This documentation file explains how to start a development server on your This documentation file explains how to start a development server on your
machine, and how it works under the hood. machine, and how it works under the hood.

@ -2,8 +2,8 @@
"name": "iqball_web", "name": "iqball_web",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"type": "module",
"dependencies": { "dependencies": {
"@loadable/component": "^5.16.3",
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
@ -28,7 +28,6 @@
"tsc": "tsc" "tsc": "tsc"
}, },
"devDependencies": { "devDependencies": {
"@types/loadable__component": "^5.13.8",
"@typescript-eslint/eslint-plugin": "^6.11.0", "@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0", "@typescript-eslint/parser": "^6.11.0",
"@vitejs/plugin-react": "^4.1.0", "@vitejs/plugin-react": "^4.1.0",

@ -1,17 +1,17 @@
import { BrowserRouter, Outlet, Route, Routes } from "react-router-dom" import { BrowserRouter, Outlet, Route, Routes } from "react-router-dom"
import loadable from "@loadable/component"
import { Header } from "./pages/template/Header.tsx" import { Header } from "./pages/template/Header.tsx"
import "./style/app.css" import "./style/app.css"
import { lazy } from "react"
const HomePage = loadable(() => import("./pages/HomePage.tsx")) const HomePage = lazy(() => import("./pages/HomePage.tsx"))
const LoginPage = loadable(() => import("./pages/LoginPage.tsx")) const LoginPage = lazy(() => import("./pages/LoginPage.tsx"))
const RegisterPage = loadable(() => import("./pages/RegisterPage.tsx")) const RegisterPage = lazy(() => import("./pages/RegisterPage.tsx"))
const NotFoundPage = loadable(() => import("./pages/404.tsx")) const NotFoundPage = lazy(() => import("./pages/404.tsx"))
const CreateTeamPage = loadable(() => import("./pages/CreateTeamPage.tsx")) const CreateTeamPage = lazy(() => import("./pages/CreateTeamPage.tsx"))
const TeamPanelPage = loadable(() => import("./pages/TeamPanel.tsx")) const TeamPanelPage = lazy(() => import("./pages/TeamPanel.tsx"))
const NewTacticPage = loadable(() => import("./pages/NewTacticPage.tsx")) const NewTacticPage = lazy(() => import("./pages/NewTacticPage.tsx"))
const Editor = loadable(() => import("./pages/Editor.tsx")) const Editor = lazy(() => import("./pages/Editor.tsx"))
export default function App() { export default function App() {
return ( return (

@ -9,7 +9,7 @@ export async function fetchAPI(
url: string, url: string,
payload: unknown, payload: unknown,
method = "POST", method = "POST",
redirectIfNotAuth: boolean = true, redirectIfUnauthorized: boolean = true,
): Promise<Response> { ): Promise<Response> {
const session = getSession() const session = getSession()
const token = session?.auth?.token const token = session?.auth?.token
@ -29,7 +29,7 @@ export async function fetchAPI(
body: JSON.stringify(payload), body: JSON.stringify(payload),
}) })
return await handleResponse(session, response, redirectIfNotAuth) return await handleResponse(session, response, redirectIfUnauthorized)
} }
export async function fetchAPIGet( export async function fetchAPIGet(

@ -17,7 +17,7 @@ export default function LoginApp() {
const email = emailRef.current!.value const email = emailRef.current!.value
const password = passwordRef.current!.value const password = passwordRef.current!.value
const response = await fetchAPI("auth/token", { email, password }) const response = await fetchAPI("auth/token", { email, password }, "POST", false)
if (response.ok) { if (response.ok) {
const session = getSession() const session = getSession()
@ -27,6 +27,12 @@ export default function LoginApp() {
return return
} }
// if unauthorized :
if (response.status === 401) {
setErrors([{ type: "Non autorisé", messages: ["L'adresse email ou le mot de passe sont invalide."] }])
return
}
try { try {
const failures = await response.json() const failures = await response.json()
setErrors( setErrors(

Loading…
Cancel
Save