From 6ebab7642dbd9c3db984c1f9a204539111ca0abf Mon Sep 17 00:00:00 2001 From: Alix Jaugey Date: Thu, 21 Mar 2024 15:40:20 +0100 Subject: [PATCH 1/2] Fix login error handling in AuthManager --- FRONT/js/data/dao/AuthDao.js | 8 ++++++-- FRONT/js/model/auth/AuthManager.js | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/FRONT/js/data/dao/AuthDao.js b/FRONT/js/data/dao/AuthDao.js index 14139cd..a598b22 100644 --- a/FRONT/js/data/dao/AuthDao.js +++ b/FRONT/js/data/dao/AuthDao.js @@ -26,7 +26,9 @@ class AuthDao extends Dao { */ async login(user) { let resp = await this.post('/login', user); - return await resp.text(); + if (resp.status === 200) { + return await resp.text(); + } } /** @@ -44,7 +46,9 @@ class AuthDao extends Dao { */ async register(user) { let resp = await this.post('/register', user); - return await resp.text(); + if (resp.status === 200) { + return await resp.text(); + } } /** diff --git a/FRONT/js/model/auth/AuthManager.js b/FRONT/js/model/auth/AuthManager.js index 9de38cd..a6e5978 100644 --- a/FRONT/js/model/auth/AuthManager.js +++ b/FRONT/js/model/auth/AuthManager.js @@ -68,6 +68,7 @@ class AuthManager { */ async login(user) { let response = await this.dao.login(user); + if (!response) throw new Error('Login failed'); this.#setToken(response); } @@ -78,6 +79,7 @@ class AuthManager { */ async register(user) { let response = await this.dao.register(user); + if (!response) throw new Error('Login failed'); this.#setToken(response); } From a3eaab9a4ab179fedc0f14b82fbe19654a5107c9 Mon Sep 17 00:00:00 2001 From: Alix Jaugey Date: Thu, 21 Mar 2024 15:41:37 +0100 Subject: [PATCH 2/2] Update status check in register method --- FRONT/js/data/dao/AuthDao.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FRONT/js/data/dao/AuthDao.js b/FRONT/js/data/dao/AuthDao.js index a598b22..c3e42a7 100644 --- a/FRONT/js/data/dao/AuthDao.js +++ b/FRONT/js/data/dao/AuthDao.js @@ -46,7 +46,7 @@ class AuthDao extends Dao { */ async register(user) { let resp = await this.post('/register', user); - if (resp.status === 200) { + if (resp.status === 201) { return await resp.text(); } }