From e817874b989cc55d2b4a0b22f2f533f173900ddc Mon Sep 17 00:00:00 2001 From: mi1468 Date: Tue, 20 May 2025 10:03:05 +0330 Subject: [PATCH] fix api with new login and getinfo api --- xroom-dashboard/src/pages/LoginPage.vue | 28 +++++++++++-------- xroom-dashboard/src/pages/dashboard/files.vue | 4 +-- xroom-dashboard/src/router/index.js | 4 +-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/xroom-dashboard/src/pages/LoginPage.vue b/xroom-dashboard/src/pages/LoginPage.vue index 871ee8c..eef0691 100644 --- a/xroom-dashboard/src/pages/LoginPage.vue +++ b/xroom-dashboard/src/pages/LoginPage.vue @@ -65,19 +65,25 @@ export default { }; try { - const response = await apiClient.post('/login', loginData); // Only endpoint path needed - const token = response.data.token; - const user = response.data.user; + const response = await apiClient.post('/login', loginData); + + if (response.data.status === 200) { + const token = response.data.data.token; + const user = response.data.data.user; - localStorage.setItem('token', token); - localStorage.setItem('user', JSON.stringify(user)); + localStorage.setItem('token', token); + localStorage.setItem('user', JSON.stringify(user)); + + this.$router.push('/dashboard'); + } else { + alert(response.data.message || 'خطا در ورود. لطفا دوباره تلاش کنید.'); + } + } catch (error) { + console.error('Login error:', error); + alert('خطا در ورود. لطفا دوباره تلاش کنید.'); + } +} - this.$router.push('/dashboard'); - } catch (error) { - console.error('Login error:', error); - alert('خطا در ورود. لطفا دوباره تلاش کنید.'); - } -}, }, }; diff --git a/xroom-dashboard/src/pages/dashboard/files.vue b/xroom-dashboard/src/pages/dashboard/files.vue index f2b06b2..7542ceb 100644 --- a/xroom-dashboard/src/pages/dashboard/files.vue +++ b/xroom-dashboard/src/pages/dashboard/files.vue @@ -462,12 +462,12 @@ export default { try { const token = localStorage.getItem('token'); - const response = await axios.get(`${this.baseUrl}/getInfo`, { + let response = await axios.get(`${this.baseUrl}/getInfo`, { headers: { 'Authorization': `Token ${token}` } }); - + response = response.data; this.userData = response.data; } catch (error) { console.error('Error fetching user data:', error); diff --git a/xroom-dashboard/src/router/index.js b/xroom-dashboard/src/router/index.js index 39d9b9b..d3a5e6a 100644 --- a/xroom-dashboard/src/router/index.js +++ b/xroom-dashboard/src/router/index.js @@ -92,8 +92,8 @@ router.beforeEach(async (to, from, next) => { if (token) { try { // Make getInfo request - const response = await axios.get('/getInfo'); - + let response = await axios.get('/getInfo'); + response = response.data; // Save customer and user data to localStorage if (response.data?.customer) { localStorage.setItem('customer', JSON.stringify(response.data.customer));