mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-19 11:14:06 +00:00
Fix CSRF token mismatch after logout by refreshing cookie
After logout invalidates the session, the SPA still holds the old CSRF cookie. Subsequent login attempts succeed but bootstrap/API calls fail with CSRF mismatch, causing redirect back to login. Fix: fetch a fresh CSRF cookie via /sanctum/csrf-cookie after logout completes.
This commit is contained in:
10
resources/scripts/admin/stores/auth.js
vendored
10
resources/scripts/admin/stores/auth.js
vendored
@@ -46,20 +46,24 @@ export const useAuthStore = (useWindow = false) => {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
http
|
http
|
||||||
.post('/auth/logout')
|
.post('/auth/logout')
|
||||||
.then((response) => {
|
.then(async (response) => {
|
||||||
const notificationStore = useNotificationStore()
|
const notificationStore = useNotificationStore()
|
||||||
notificationStore.showNotification({
|
notificationStore.showNotification({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: 'Logged out successfully.',
|
message: 'Logged out successfully.',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Refresh CSRF token so next login works cleanly
|
||||||
|
await http.get('/sanctum/csrf-cookie').catch(() => {})
|
||||||
|
|
||||||
window.router.push('/login')
|
window.router.push('/login')
|
||||||
// resetStore.clearPinia()
|
|
||||||
resolve(response)
|
resolve(response)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
handleError(err)
|
handleError(err)
|
||||||
window.router.push('/')
|
// Still refresh CSRF and redirect on error
|
||||||
|
http.get('/sanctum/csrf-cookie').catch(() => {})
|
||||||
|
window.router.push('/login')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user