diff --git a/README.md b/README.md index f48443c..889ae9d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Créez un fichier `.env` dans le dossier `server` et ajoutez les variables d'env ```env PORT=3001 -MONGODB_URI=your_mongodb_uri_here +MONGO_URI=your_mongodb_uri_here ``` ### 4. Configuration du Frontend @@ -63,4 +63,4 @@ L'application sera accessible à l'adresse http://localhost:5173 dans votre navi ## Comment Installer MongoDB -Suivez les instructions sur le site officiel de MongoDB pour installer la base de données : [MongoDB Installation Guide](https://www.mongodb.com/docs/manual/installation/) +Suivez les instructions sur cette vidéo pour installer MongoDB : [MongoDB Installation Guide](https://www.youtube.com/watch?v=gB6WLkSrtJk) diff --git a/client/htaccess b/client/public/htaccess similarity index 100% rename from client/htaccess rename to client/public/htaccess diff --git a/client/src/pages/map/MapPage.tsx b/client/src/pages/map/MapPage.tsx index c73b0e4..e667000 100644 --- a/client/src/pages/map/MapPage.tsx +++ b/client/src/pages/map/MapPage.tsx @@ -46,32 +46,44 @@ const MapPage = () => { }; const getFlamiLocation = useCallback(() => { - APIHandler("/my/flami?trail", false, "GET", undefined, token).then( - async (res) => { - if (!res.data.my_flami?.location?.latitude || - !res.data.my_flami?.location?.longitude) { - return setFlamiLocation(null); - } else { - setFlamiTrail(res.data.my_flami?.trail?.map(e => [e.latitude, e.longitude])); - setFlamiPosition(res.data.my_flami?.location); - await fetch(`https://api-adresse.data.gouv.fr/reverse/?lat=${res.data.my_flami.location.latitude}&lon=${res.data.my_flami.location.longitude}`).then((res) => - res.json().then((data) => { - if (data.features?.length > 0) { - const context = - data.features[0]["properties"]["context"].split(", "); - setFlamiLocation({ - ville: data.features[0]["properties"]["city"], - dept: `${context[1]} (${context[0]})`, - region: context[2], - }); - } else { - setFlamiLocation(null); - } - }) - ).catch(() => setFlamiLocation(null)); - } + APIHandler( + "/my/flami?trail", + false, + "GET", + undefined, + token + ).then(async (res) => { + if ( + !res.data.my_flami?.location?.latitude || + !res.data.my_flami?.location?.longitude + ) { + return setFlamiLocation(null); + } else { + setFlamiTrail( + res.data.my_flami?.trail?.map((e) => [e.latitude, e.longitude]) + ); + setFlamiPosition(res.data.my_flami?.location); + await fetch( + `https://api-adresse.data.gouv.fr/reverse/?lat=${res.data.my_flami.location.latitude}&lon=${res.data.my_flami.location.longitude}` + ) + .then((res) => + res.json().then((data) => { + if (data.features?.length > 0) { + const context = + data.features[0]["properties"]["context"].split(", "); + setFlamiLocation({ + ville: data.features[0]["properties"]["city"], + dept: `${context[1]} (${context[0]})`, + region: context[2], + }); + } else { + setFlamiLocation(null); + } + }) + ) + .catch(() => setFlamiLocation(null)); } - ); + }); }, [token]); useEffect(() => { diff --git a/client/src/utils/api/api-handler.ts b/client/src/utils/api/api-handler.ts index 771195c..cefe96e 100644 --- a/client/src/utils/api/api-handler.ts +++ b/client/src/utils/api/api-handler.ts @@ -4,7 +4,7 @@ import toast from "react-hot-toast"; type HTTPMethod = "GET" | "POST" | "PATCH"; -const apiURLFlami = "http://localhost:3001/api"; +const apiURLFlami = "https://flami-api.onrender.com/api"; const apiURLMap = "https://maksance.alwaysdata.net/api-jo"; export const APIHandler = ( @@ -47,8 +47,8 @@ export const APIHandler = ( }, }); }); - - if(res.status === 401) { + + if (res.status === 401) { localStorage.clear(); window.location.pathname = "/sign-in"; } diff --git a/server/__test__/Api.test.js b/server/__test__/Api.test.js new file mode 100644 index 0000000..9375cad --- /dev/null +++ b/server/__test__/Api.test.js @@ -0,0 +1,7 @@ +import { describe, it, expect } from "vitest"; + +describe("Simple test :D", () => { + it("should pass", () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/server/controllers/auth.controller.js b/server/controllers/auth.controller.js index 2f42f2a..6869864 100644 --- a/server/controllers/auth.controller.js +++ b/server/controllers/auth.controller.js @@ -112,7 +112,7 @@ const authController = { if (isValid) { let token = auth.encode({ email: user.email }); - req.brute.reset(); // reset brute counter + // req.brute.reset(); return res.status(200).json({ data: { message: "Bienvenue sur l'application Flami !", diff --git a/server/routes/auth.routes.js b/server/routes/auth.routes.js index 68821e3..3b56036 100644 --- a/server/routes/auth.routes.js +++ b/server/routes/auth.routes.js @@ -14,7 +14,7 @@ if (process.env.ENVIRONMENT == "dev") { store = new ExpressBrute.MemoryStore(); // stores state locally, don't use this in production } else { // stores state with memcached - store = new MemcachedStore(["127.0.0.1"], { + store = new MemcachedStore(["127.0.0.1:11211"], { prefix: "NoConflicts", }); } @@ -38,21 +38,21 @@ let handleStoreError = function (error) { }; let bruteforce = new ExpressBrute(store, { - freeRetries: 1000, + freeRetries: 5, minWait: 5 * 60 * 1000, // 5 minutes maxWait: 10 * 60 * 1000, // 1 hour, failCallback: failCallback, handleStoreError: handleStoreError, }); -router.post("/signin", bruteforce.prevent, authController.signin); -router.post("/signup", bruteforce.prevent, authController.signup); +router.post("/signin", authController.signin); +router.post("/signup", authController.signup); router.get("/token", auth.require, authController.token); -router.post("/send-otp", bruteforce.prevent, otpController.sendOTP); -router.post("/verify-otp", bruteforce.prevent, otpController.verifyOTP); -router.post("/forget-password", bruteforce.prevent, forgetPasswordController.forgetPassword); -router.post("/reset-password/:token", bruteforce.prevent, forgetPasswordController.resetPassword); +router.post("/send-otp", otpController.sendOTP); +router.post("/verify-otp", otpController.verifyOTP); +router.post("/forget-password", forgetPasswordController.forgetPassword); +router.post("/reset-password/:token", forgetPasswordController.resetPassword); export default router; diff --git a/server/server.js b/server/server.js index 25a99d7..bb3fb6e 100644 --- a/server/server.js +++ b/server/server.js @@ -1,4 +1,3 @@ -import cookieParser from "cookie-parser"; import cors from "cors"; import dotenv from "dotenv"; import express from "express"; @@ -16,7 +15,6 @@ dotenv.config(); const app = express(); app.use(express.json()); -app.use(cookieParser()); app.use(cors());