first commit
This commit is contained in:
20
app/plugins/01.fetch_setting.ts
Normal file
20
app/plugins/01.fetch_setting.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { Setting } from "~~/types/setting";
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
|
||||
|
||||
const { useSettingStore } = await import('@/stores/setting')
|
||||
const settingStore = useSettingStore()
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const apiUrl = config.public.BASE_API_URL;
|
||||
|
||||
try {
|
||||
const data = await $fetch<Setting>(`${apiUrl}/api/v1/setting`)
|
||||
if (data) {
|
||||
settingStore.setSettings(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch settings:', error)
|
||||
}
|
||||
})
|
||||
20
app/plugins/02.fetch_hero.ts
Normal file
20
app/plugins/02.fetch_hero.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { Hero } from "~~/types/hero";
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
|
||||
|
||||
const { useHeroStore } = await import('@/stores/hero')
|
||||
const heroStore = useHeroStore()
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const apiUrl = config.public.BASE_API_URL;
|
||||
|
||||
try {
|
||||
const data = await $fetch<Hero>(`${apiUrl}/api/v1/hero`)
|
||||
if (data) {
|
||||
heroStore.setHero(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch settings:', error)
|
||||
}
|
||||
})
|
||||
11
app/plugins/auth-error.ts
Normal file
11
app/plugins/auth-error.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const { data, signOut } = useAuth();
|
||||
|
||||
// Watch for session changes
|
||||
watch(data, async (session) => {
|
||||
if (session?.error === 'RefreshAccessTokenError') {
|
||||
console.warn('Refresh token expired or invalid. Signing out...');
|
||||
await signOut({ callbackUrl: '/auth/login' });
|
||||
}
|
||||
}, { immediate: true });
|
||||
});
|
||||
7
app/plugins/fontawesome.client.ts
Normal file
7
app/plugins/fontawesome.client.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// Converted to a no-op: we register Font Awesome using an SSR-aware plugin `app/plugins/fontawesome.ts`.
|
||||
// Keep this client-only file present (if you relied on it elsewhere) but do not inject the runtime script
|
||||
// to avoid hydration mismatches.
|
||||
export default defineNuxtPlugin(() => {
|
||||
if (process.server) return
|
||||
// No-op on client — FontAwesome is registered via app/plugins/fontawesome.ts
|
||||
})
|
||||
39
app/plugins/fontawesome.ts
Normal file
39
app/plugins/fontawesome.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
// SSR-friendly Font Awesome plugin
|
||||
// Registers the Vue component and a small set of icons so server-render and client-render match.
|
||||
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||
// Import a conservative set of icons used in the admin UI
|
||||
import {
|
||||
faHouse,
|
||||
faUsers,
|
||||
faCogs,
|
||||
faNewspaper,
|
||||
faTags,
|
||||
faHashtag,
|
||||
faRightFromBracket,
|
||||
faPlus,
|
||||
faWandMagic,
|
||||
faGaugeHigh,
|
||||
faShieldAlt
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
// Add selected icons to the library
|
||||
library.add(
|
||||
faHouse,
|
||||
faUsers,
|
||||
faCogs,
|
||||
faNewspaper,
|
||||
faTags,
|
||||
faHashtag,
|
||||
faRightFromBracket,
|
||||
faPlus,
|
||||
faWandMagic,
|
||||
faGaugeHigh,
|
||||
faShieldAlt
|
||||
)
|
||||
|
||||
// Globally register component
|
||||
nuxtApp.vueApp.component('FontAwesomeIcon', FontAwesomeIcon)
|
||||
})
|
||||
|
||||
5
app/plugins/sweetalert2.client.ts
Normal file
5
app/plugins/sweetalert2.client.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import Swal from 'sweetalert2'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.provide('swal', Swal)
|
||||
})
|
||||
Reference in New Issue
Block a user