feat(settings): Add independent plugin to put loading system configuration in the lifecycle hook "app:created".
This commit is contained in:
6
plugins/initApiKey.js
Normal file
6
plugins/initApiKey.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.hook('app:created', async () => {
|
||||
const apiKey = useApiKey()
|
||||
apiKey.value = getStoredApiKey()
|
||||
})
|
||||
})
|
||||
24
plugins/settings.js
Normal file
24
plugins/settings.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const transformData = (list) => {
|
||||
const result = {};
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const item = list[i];
|
||||
result[item.name] = item.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.hook('app:created', async () => {
|
||||
let settings = {}
|
||||
|
||||
const { data, error } = await useAuthFetch('/api/chat/settings/', {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
if (!error.value) {
|
||||
settings = transformData(data.value)
|
||||
}
|
||||
|
||||
nuxtApp.provide('settings', settings)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user