fix: add logout button to vendor onboarding page

The onboarding page was a standalone page with no way to log out,
leaving users stuck. Added:
- Logout button in the header
- handleLogout() function to clear vendor tokens and redirect to login

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-28 18:30:13 +01:00
parent 81e5cb41d6
commit b8fcc3a196
2 changed files with 35 additions and 0 deletions

View File

@@ -23,6 +23,12 @@
</div>
<span class="text-xl font-semibold text-gray-800 dark:text-white">Wizamart</span>
</div>
<!-- Logout Button -->
<button @click="handleLogout()"
class="mr-4 px-3 py-2 text-sm font-medium text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors">
Logout
</button>
<!-- Language Selector -->
<div class="relative" x-data="{ open: false }">
<button @click="open = !open"

View File

@@ -603,6 +603,35 @@ function vendorOnboarding(initialLang = 'en') {
}
},
// Logout handler
async handleLogout() {
console.log('🚪 Logging out from onboarding...');
// Get vendor code from URL
const path = window.location.pathname;
const segments = path.split('/').filter(Boolean);
const vendorCode = segments[0] === 'vendor' && segments[1] ? segments[1] : '';
try {
// Call logout API
await apiClient.post('/vendor/auth/logout');
console.log('✅ Logout API called successfully');
} catch (error) {
console.error('⚠️ Logout API error (continuing anyway):', error);
} finally {
// Clear vendor tokens only (not admin or customer tokens)
console.log('🧹 Clearing vendor tokens...');
localStorage.removeItem('vendor_token');
localStorage.removeItem('vendor_user');
localStorage.removeItem('currentUser');
localStorage.removeItem('vendorCode');
// Note: Do NOT use localStorage.clear() - it would clear admin/customer tokens too
console.log('🔄 Redirecting to login...');
window.location.href = `/vendor/${vendorCode}/login`;
}
},
// Dark mode
get dark() {
return localStorage.getItem('dark') === 'true' ||