From 21de520175e748d342852d4a71efc8e7c7fd998e Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 9 Mar 2024 10:29:32 +0100 Subject: [PATCH 1/4] Fixing the cross origine on the frontend side --- frontend/src/rest/Users.js | 2 +- frontend/src/rest/restConsumer.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/rest/Users.js b/frontend/src/rest/Users.js index e34d611..bcbf8b9 100644 --- a/frontend/src/rest/Users.js +++ b/frontend/src/rest/Users.js @@ -1,7 +1,7 @@ import { restGet, restPost } from './restConsumer.js' export async function login(user, pass, exp){ - return restPost("/login", {login: user, password: pass, expiration: exp}); + return restPost("/login", {identifier: user, password: pass, expiration: exp}); } export async function register(user, pass, mail){ diff --git a/frontend/src/rest/restConsumer.js b/frontend/src/rest/restConsumer.js index 25729bd..63a0a0d 100644 --- a/frontend/src/rest/restConsumer.js +++ b/frontend/src/rest/restConsumer.js @@ -8,15 +8,15 @@ export async function restGet(endPoint) { } export async function restPost(endPoint, data) { - return await _rest(endPoint, {method: "POST", body: data}); + return await _rest(endPoint, {method: "POST", body: JSON.stringify(data)}); } export async function restDelete(endPoint, data) { - return await _rest(endPoint, {method: "DELETE", body: data}); + return await _rest(endPoint, {method: "DELETE", body: JSON.stringify(data)}); } export async function restPatch(endPoint, data) { - return await _rest(endPoint, {method: "PATCH", body: data}); + return await _rest(endPoint, {method: "PATCH", body: JSON.stringify(data)); } /** @@ -31,8 +31,12 @@ export async function restPatch(endPoint, data) { async function _rest(endPoint, config){ endPoint.at(0) != "/" ? console.error("Carefull, you certainly should put a / at the begenning of your endPoint ") : true; let session_token = getCookie("session_token"); - let headers = new Headers({'Authorization': session_token}); + let headers = new Headers({ + 'Authorization': session_token, + 'Content-Type': 'application/json', + }); config['headers'] = headers; + config['credentials'] = 'include' return toast.promise(fetch(restURL + endPoint, config), { pending: config['pending'] != null ? config['pending'] : 'pending', -- 2.46.0 From 0b4b38f6c555180320ef94b41206a4c497ef9050 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 9 Mar 2024 10:36:20 +0100 Subject: [PATCH 2/4] Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merci javascript pour ces erreurs de qualitée... --- frontend/src/rest/restConsumer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/rest/restConsumer.js b/frontend/src/rest/restConsumer.js index 63a0a0d..9e42e49 100644 --- a/frontend/src/rest/restConsumer.js +++ b/frontend/src/rest/restConsumer.js @@ -16,7 +16,7 @@ export async function restDelete(endPoint, data) { } export async function restPatch(endPoint, data) { - return await _rest(endPoint, {method: "PATCH", body: JSON.stringify(data)); + return await _rest(endPoint, {method: "PATCH", body: JSON.stringify(data)}); } /** -- 2.46.0 From 847b1ca4194023c352c3d966b1cb7d230a5da0bb Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 9 Mar 2024 16:20:55 +0100 Subject: [PATCH 3/4] Solve crossOrigin Finally --- .../main/java/ovh/herisson/Clyde/EndPoints/LoginController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index 8a0722d..8c687ee 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -9,7 +9,7 @@ import ovh.herisson.Clyde.Services.AuthenticatorService; import java.util.Date; @RestController -@CrossOrigin(origins = "http://localhost:5173") +@CrossOrigin(origins = "http://localhost:5173", allowCredentials = "true") public class LoginController { private final AuthenticatorService authServ; -- 2.46.0 From ac8830703698f317bdf5ec3972722d36d4efd7fc Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 9 Mar 2024 16:22:38 +0100 Subject: [PATCH 4/4] fix expiration date and frontend requests --- frontend/src/rest/Users.js | 2 +- frontend/src/rest/restConsumer.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/rest/Users.js b/frontend/src/rest/Users.js index bcbf8b9..cca662d 100644 --- a/frontend/src/rest/Users.js +++ b/frontend/src/rest/Users.js @@ -1,7 +1,7 @@ import { restGet, restPost } from './restConsumer.js' export async function login(user, pass, exp){ - return restPost("/login", {identifier: user, password: pass, expiration: exp}); + return restPost("/login", {identifier: user, password: pass, expirationDate: exp}); } export async function register(user, pass, mail){ diff --git a/frontend/src/rest/restConsumer.js b/frontend/src/rest/restConsumer.js index 9e42e49..b2d1546 100644 --- a/frontend/src/rest/restConsumer.js +++ b/frontend/src/rest/restConsumer.js @@ -8,15 +8,15 @@ export async function restGet(endPoint) { } export async function restPost(endPoint, data) { - return await _rest(endPoint, {method: "POST", body: JSON.stringify(data)}); + return await _rest(endPoint, {method: "POST", credentials: 'include', body: JSON.stringify(data)}); } export async function restDelete(endPoint, data) { - return await _rest(endPoint, {method: "DELETE", body: JSON.stringify(data)}); + return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)}); } export async function restPatch(endPoint, data) { - return await _rest(endPoint, {method: "PATCH", body: JSON.stringify(data)}); + return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)}); } /** @@ -36,7 +36,6 @@ async function _rest(endPoint, config){ 'Content-Type': 'application/json', }); config['headers'] = headers; - config['credentials'] = 'include' return toast.promise(fetch(restURL + endPoint, config), { pending: config['pending'] != null ? config['pending'] : 'pending', -- 2.46.0