Improve the conversation process
This commit is contained in:
18
composables/fetch.js
Normal file
18
composables/fetch.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export const useMyFetch = (url, options = {}) => {
|
||||
let defaultOptions = {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
}
|
||||
}
|
||||
if (process.server) {
|
||||
defaultOptions.baseURL = process.env.SERVER_DOMAIN
|
||||
}
|
||||
return useFetch(url, Object.assign(defaultOptions, options))
|
||||
}
|
||||
export const useAuthFetch = async (url, options = {}) => {
|
||||
const res = await useMyFetch(url, options)
|
||||
if (res.error.value && res.error.value.status === 401) {
|
||||
await logout()
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -9,6 +9,6 @@ export const useConversation = () => useState('conversation', () => getDefaultCo
|
||||
|
||||
export const useConversations = () => useState('conversations', () => [])
|
||||
|
||||
export const useSettings = () => useState('settings', () => {})
|
||||
export const useSettings = () => useState('settings', () => getSystemSettings())
|
||||
|
||||
export const useUser = () => useState('user', () => null)
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
export const useAuthFetch = async (url, options = {}) => {
|
||||
const res = await useFetch(url, options)
|
||||
if (res.error.value && res.error.value.status === 401) {
|
||||
await logout()
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user