Skip to content

Commit

Permalink
refactor checkAndRedirect function to handle multiple redirections an…
Browse files Browse the repository at this point in the history
…d handle /order-details path
  • Loading branch information
emipallares committed Nov 29, 2024
1 parent f9dbb14 commit 021bd0a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions blocks/header/renderAuthDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { events } from '@dropins/tools/event-bus.js';
import { getCookie } from '../../scripts/configs.js';
import { CUSTOMER_FORGOTPASSWORD_PATH } from '../../scripts/constants.js';

function checkAndRedirect(checkUrl, redirectUrl) {
// If the user is on the dashboard page and initiates logout,
// they will be redirected to the login page.
const currentUrl = window.location.pathname;

if (currentUrl.includes(checkUrl)) {
window.location.href = `${window.location.origin}${redirectUrl}`;
}
function checkAndRedirect(redirections) {
Object.entries(redirections).some(([currentPath, redirectPath]) => {
if (window.location.pathname.includes(currentPath)) {
window.location.href = redirectPath;
return true;
}
return false;
});
}

function renderSignIn(element) {
Expand Down Expand Up @@ -68,7 +68,10 @@ export function renderAuthDropdown(navTools) {

logoutButtonElement.addEventListener('click', async () => {
await authApi.revokeCustomerToken();
checkAndRedirect('/customer', '/customer/login');
checkAndRedirect({
'/customer': '/customer/login',
'/order-details': '/',
});
});

renderSignIn(authDropinContainer);
Expand Down

0 comments on commit 021bd0a

Please sign in to comment.