diff --git a/src/lib/common/ProfileDropdown.svelte b/src/lib/common/ProfileDropdown.svelte index 9c7e9267..0ae88a33 100644 --- a/src/lib/common/ProfileDropdown.svelte +++ b/src/lib/common/ProfileDropdown.svelte @@ -11,7 +11,7 @@ function logout() { if (browser){ localStorage.removeItem('user'); - } + } goto('login'); }; @@ -39,8 +39,13 @@ /> {$_('Settings')} - -
+ +
{}} + on:click={logout} + > {$_('Logout')}
diff --git a/src/lib/helpers/http.js b/src/lib/helpers/http.js index 1f02b3a7..767cf4d3 100644 --- a/src/lib/helpers/http.js +++ b/src/lib/helpers/http.js @@ -39,7 +39,12 @@ axios.interceptors.response.use( if (error.response && error.response.status === 401) { // Perform actions like redirecting to the login page or refreshing tokens // Example: redirect to the login page - window.location.href = 'login'; + const curUrl = window.location.pathname + window.location.search; + let loginUrl = 'login'; + if (curUrl) { + loginUrl += `?redirect=${encodeURIComponent(curUrl)}`; + } + window.location.href = loginUrl; } // Return the error to the calling function diff --git a/src/routes/(authentication)/login/+page.svelte b/src/routes/(authentication)/login/+page.svelte index 07e82e37..3cf74ae4 100644 --- a/src/routes/(authentication)/login/+page.svelte +++ b/src/routes/(authentication)/login/+page.svelte @@ -16,6 +16,7 @@ import Headtitle from '$lib/common/HeadTitle.svelte'; import { getToken } from '$lib/services/auth-service.js'; import { goto } from '$app/navigation'; + import { page } from '$app/stores'; import { PUBLIC_SERVICE_URL, PUBLIC_LIVECHAT_HOST, @@ -59,7 +60,12 @@ isOpen = true; msg = 'Authentication success'; status = 'success'; - goto('page/dashboard'); + const redirectUrl = $page.url.searchParams.get('redirect'); + if (redirectUrl) { + window.location.href = decodeURIComponent(redirectUrl); + } else { + goto('page/dashboard'); + } isSubmitting = false; }); isSubmitting = false; @@ -146,8 +152,9 @@ type="button" id="password-addon" on:click={() => onPasswordToggle()} - > + +
@@ -166,8 +173,10 @@ color="primary" disabled={isSubmitting} class="waves-effect waves-light" - type="submit">{!isSubmitting ? 'Log In' : 'Log In...'} + {!isSubmitting ? 'Log In' : 'Log In...'} +