WIP jordan
This commit is contained in:
20
app/plugins/open-fetch-policy-auth.ts
Normal file
20
app/plugins/open-fetch-policy-auth.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export default defineNuxtPlugin({
|
||||
name: 'open-fetch-policy-auth',
|
||||
setup(nuxtApp) {
|
||||
const { policyApiToken } = useRuntimeConfig().public
|
||||
const token = typeof policyApiToken === 'string' ? policyApiToken : ''
|
||||
if (!token) return
|
||||
|
||||
nuxtApp.hook('openFetch:onRequest:policy', (ctx) => {
|
||||
const headers = ctx.options.headers
|
||||
if (headers instanceof Headers) {
|
||||
if (!headers.has('Authorization')) headers.set('Authorization', `Bearer ${token}`)
|
||||
} else {
|
||||
const h = (headers ?? {}) as Record<string, string>
|
||||
if (!h.Authorization && !h.authorization) {
|
||||
ctx.options.headers = { ...h, Authorization: `Bearer ${token}` }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
11
app/plugins/theme-hydrate.client.ts
Normal file
11
app/plugins/theme-hydrate.client.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/** Apply saved theme before paint to reduce flash (pairs with useAppTheme). */
|
||||
export default defineNuxtPlugin(() => {
|
||||
try {
|
||||
const t = localStorage.getItem('policy-ui.theme.v1')
|
||||
if (t && ['light', 'purple', 'dark', 'dark-purple'].includes(t)) {
|
||||
document.documentElement.setAttribute('data-theme', t)
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user