mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-16 17:54:06 +00:00
Fix logout not clearing auth token and company from localStorage
After logout, the old auth.token and selectedCompany stayed in localStorage. On next login, the http interceptor sent the stale token in the Authorization header, causing all API calls to fail with 401/419 even though the new session was valid.
This commit is contained in:
7
resources/scripts/admin/stores/auth.js
vendored
7
resources/scripts/admin/stores/auth.js
vendored
@@ -53,6 +53,10 @@ export const useAuthStore = (useWindow = false) => {
|
||||
message: 'Logged out successfully.',
|
||||
})
|
||||
|
||||
// Clear stored auth data so next login doesn't send stale tokens
|
||||
window.Ls.remove('auth.token')
|
||||
window.Ls.remove('selectedCompany')
|
||||
|
||||
// Refresh CSRF token so next login works cleanly
|
||||
await http.get('/sanctum/csrf-cookie').catch(() => {})
|
||||
|
||||
@@ -61,7 +65,8 @@ export const useAuthStore = (useWindow = false) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
// Still refresh CSRF and redirect on error
|
||||
window.Ls.remove('auth.token')
|
||||
window.Ls.remove('selectedCompany')
|
||||
http.get('/sanctum/csrf-cookie').catch(() => {})
|
||||
window.router.push('/login')
|
||||
reject(err)
|
||||
|
||||
Reference in New Issue
Block a user