Skip to content

Commit a93972b

Browse files
author
Jicheng Lu
committed
add redirect
1 parent e3021ea commit a93972b

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/lib/common/ProfileDropdown.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
function logout() {
1212
if (browser){
1313
localStorage.removeItem('user');
14-
}
14+
}
1515
goto('login');
1616
};
1717
</script>
@@ -39,8 +39,13 @@
3939
/> <span key="t-settings">{$_('Settings')}</span>
4040
</DropdownItem>
4141
<DropdownItem divider />
42-
<DropdownItem href="#" on:click={logout}>
43-
<div>
42+
<DropdownItem href="#">
43+
<div
44+
role="button"
45+
tabindex="0"
46+
on:keydown={() => {}}
47+
on:click={logout}
48+
>
4449
<i class="bx bx-power-off font-size-16 align-middle me-1 text-danger" /> <span>{$_('Logout')}</span>
4550
</div>
4651
</DropdownItem>

src/lib/helpers/http.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ axios.interceptors.response.use(
3939
if (error.response && error.response.status === 401) {
4040
// Perform actions like redirecting to the login page or refreshing tokens
4141
// Example: redirect to the login page
42-
window.location.href = 'login';
42+
const curUrl = window.location.pathname + window.location.search;
43+
let loginUrl = 'login';
44+
if (curUrl) {
45+
loginUrl += `?redirect=${encodeURIComponent(curUrl)}`;
46+
}
47+
window.location.href = loginUrl;
4348
}
4449

4550
// Return the error to the calling function

src/routes/(authentication)/login/+page.svelte

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import Headtitle from '$lib/common/HeadTitle.svelte';
1717
import { getToken } from '$lib/services/auth-service.js';
1818
import { goto } from '$app/navigation';
19+
import { page } from '$app/stores';
1920
import {
2021
PUBLIC_SERVICE_URL,
2122
PUBLIC_LIVECHAT_HOST,
@@ -59,7 +60,12 @@
5960
isOpen = true;
6061
msg = 'Authentication success';
6162
status = 'success';
62-
goto('page/dashboard');
63+
const redirectUrl = $page.url.searchParams.get('redirect');
64+
if (redirectUrl) {
65+
window.location.href = decodeURIComponent(redirectUrl);
66+
} else {
67+
goto('page/dashboard');
68+
}
6369
isSubmitting = false;
6470
});
6571
isSubmitting = false;
@@ -146,8 +152,9 @@
146152
type="button"
147153
id="password-addon"
148154
on:click={() => onPasswordToggle()}
149-
><i id="password-eye-icon" class="mdi mdi-eye-outline" /></Button
150155
>
156+
<i id="password-eye-icon" class="mdi mdi-eye-outline" />
157+
</Button>
151158
</div>
152159
</div>
153160

@@ -166,8 +173,10 @@
166173
color="primary"
167174
disabled={isSubmitting}
168175
class="waves-effect waves-light"
169-
type="submit">{!isSubmitting ? 'Log In' : 'Log In...'}</Button
176+
type="submit"
170177
>
178+
{!isSubmitting ? 'Log In' : 'Log In...'}
179+
</Button>
171180
</div>
172181

173182
<div class="mt-4 text-center">

0 commit comments

Comments
 (0)