feat: remember last visited page after login
Users are now redirected to their last visited page after logging in, instead of always going to the dashboard. Implementation: - Track current page in localStorage on every page load - Exclude login, logout, onboarding, and error pages from tracking - On login success, redirect to last visited page if valid - Clear last visited page on logout Admin: - static/admin/js/init-alpine.js: Save page to admin_last_visited_page - static/admin/js/login.js: Redirect to last page after login - app/templates/admin/partials/header.html: Clear on logout Vendor: - static/vendor/js/init-alpine.js: Save page to vendor_last_visited_page - static/vendor/js/login.js: Redirect to last page (validates vendor code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,24 @@ function data() {
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// Last visited page tracking (for redirect after login)
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
const LAST_PAGE_KEY = 'admin_last_visited_page';
|
||||
const currentPath = window.location.pathname;
|
||||
|
||||
// Save current page (exclude login, logout, error pages)
|
||||
if (currentPath.startsWith('/admin/') &&
|
||||
!currentPath.includes('/login') &&
|
||||
!currentPath.includes('/logout') &&
|
||||
!currentPath.includes('/errors/')) {
|
||||
try {
|
||||
window.localStorage.setItem(LAST_PAGE_KEY, currentPath);
|
||||
} catch (e) {
|
||||
// Ignore storage errors
|
||||
}
|
||||
}
|
||||
|
||||
// Map pages to their parent sections
|
||||
const pageSectionMap = {
|
||||
// Platform Administration
|
||||
|
||||
@@ -183,14 +183,18 @@ function adminLogin() {
|
||||
this.success = 'Login successful! Redirecting...';
|
||||
loginLog.info('Success message displayed to user');
|
||||
|
||||
loginLog.info('Redirecting to dashboard immediately...');
|
||||
// Check for last visited page (saved before logout)
|
||||
const lastPage = localStorage.getItem('admin_last_visited_page');
|
||||
const redirectTo = (lastPage && lastPage.startsWith('/admin/') && !lastPage.includes('/login'))
|
||||
? lastPage
|
||||
: '/admin/dashboard';
|
||||
|
||||
loginLog.info('=== EXECUTING REDIRECT ===');
|
||||
loginLog.debug('Target URL: /admin/dashboard');
|
||||
loginLog.debug('Redirect method: window.location.href');
|
||||
loginLog.debug('Last visited page:', lastPage);
|
||||
loginLog.debug('Target URL:', redirectTo);
|
||||
|
||||
// Use href instead of replace to allow back button
|
||||
// But redirect IMMEDIATELY - don't wait!
|
||||
window.location.href = '/admin/dashboard';
|
||||
window.location.href = redirectTo;
|
||||
|
||||
} catch (error) {
|
||||
window.LogConfig.logError(error, 'Login');
|
||||
|
||||
Reference in New Issue
Block a user