fix: auth race condition on refresh, section edit dialog, time slot duplicate, autocomplete disable
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import axios from 'axios'
|
||||
import type { AxiosInstance, InternalAxiosRequestConfig } from 'axios'
|
||||
import { useAuthStore } from '@/stores/useAuthStore'
|
||||
import { useNotificationStore } from '@/stores/useNotificationStore'
|
||||
import { useOrganisationStore } from '@/stores/useOrganisationStore'
|
||||
|
||||
const apiClient: AxiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL,
|
||||
@@ -15,11 +17,16 @@ const apiClient: AxiosInstance = axios.create({
|
||||
apiClient.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
const authStore = useAuthStore()
|
||||
const orgStore = useOrganisationStore()
|
||||
|
||||
if (authStore.token) {
|
||||
config.headers.Authorization = `Bearer ${authStore.token}`
|
||||
}
|
||||
|
||||
if (orgStore.activeOrganisationId) {
|
||||
config.headers['X-Organisation-Id'] = orgStore.activeOrganisationId
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`🚀 ${config.method?.toUpperCase()} ${config.url}`, config.data)
|
||||
}
|
||||
@@ -42,15 +49,40 @@ apiClient.interceptors.response.use(
|
||||
console.error(`❌ ${error.response?.status} ${error.config?.url}`, error.response?.data)
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
const status = error.response?.status
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
if (status === 401) {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
authStore.logout()
|
||||
// During initialization, let initialize() handle the 401 — skip redirect
|
||||
if (authStore.isInitialized) {
|
||||
authStore.logout()
|
||||
|
||||
if (typeof window !== 'undefined' && window.location.pathname !== '/login') {
|
||||
window.location.href = '/login'
|
||||
if (typeof window !== 'undefined' && window.location.pathname !== '/login') {
|
||||
window.location.href = '/login'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (status === 403) {
|
||||
notificationStore.show('You don\'t have permission for this action.', 'error')
|
||||
}
|
||||
else if (status === 404) {
|
||||
notificationStore.show('The requested item was not found.', 'warning')
|
||||
}
|
||||
else if (status === 422) {
|
||||
// Validation errors — pass through to calling component
|
||||
}
|
||||
else if (status === 503) {
|
||||
notificationStore.show('Service temporarily unavailable. Please try again later.', 'error')
|
||||
}
|
||||
else if (status && status >= 500) {
|
||||
notificationStore.show('An unexpected error occurred. Please try again later.', 'error')
|
||||
}
|
||||
else if (!error.response) {
|
||||
// Network error — no response received
|
||||
notificationStore.show('Unable to connect to the server. Check your internet connection.', 'error')
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
},
|
||||
|
||||
15
apps/app/src/lib/dutch-plural.ts
Normal file
15
apps/app/src/lib/dutch-plural.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Basic Dutch pluralisation for configurable event labels.
|
||||
* Covers the known sub_event_label values: Dag, Programmaonderdeel, Editie, Locatie, Ronde.
|
||||
*/
|
||||
export function dutchPlural(word: string): string {
|
||||
// Words ending in -ie: add -s (editie → edities, locatie → locaties)
|
||||
if (word.endsWith('ie')) return `${word}s`
|
||||
// Words ending in -e: add -s (ronde → rondes)
|
||||
if (word.endsWith('e')) return `${word}s`
|
||||
// Double vowel before final consonant(s): single vowel + en (onderdeel → onderdelen)
|
||||
const match = word.match(/^(.*)([aeiou])\2([^aeiou]+)$/i)
|
||||
if (match) return `${match[1]}${match[2]}${match[3]}en`
|
||||
// Default: add -en (dag → dagen)
|
||||
return `${word}en`
|
||||
}
|
||||
Reference in New Issue
Block a user