diff --git a/pages/index.vue b/pages/index.vue index a9c74f5..120d459 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -4,7 +4,7 @@ definePageMeta({ }) import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source' -const { $i18n } = useNuxtApp() +const { $i18n, $auth } = useNuxtApp() const runtimeConfig = useRuntimeConfig() const currentModel = useCurrentModel() const openaiApiKey = useApiKey() @@ -18,13 +18,16 @@ const abortFetch = () => { fetchingResponse.value = false } const fetchReply = async (message, parentMessageId) => { + const token = await $auth.retrieveToken() ctrl = new AbortController() try { await fetchEventSource('/api/conversation', { signal: ctrl.signal, method: 'POST', headers: { - 'Content-Type': 'application/json' + 'accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ model: currentModel.value, @@ -49,6 +52,7 @@ const fetchReply = async (message, parentMessageId) => { throw err; }, onmessage(message) { + console.log(message) const event = message.event const data = JSON.parse(message.data) @@ -71,7 +75,7 @@ const fetchReply = async (message, parentMessageId) => { currentConversation.value.messages.push({id: null, from: 'ai', message: data.content}) } - scrollChatWindow() + // scrollChatWindow() }, }) } catch (err) { diff --git a/plugins/auth.js b/plugins/auth.js index 2452c2f..5df17c8 100644 --- a/plugins/auth.js +++ b/plugins/auth.js @@ -26,7 +26,7 @@ const ENDPOINTS = { export default defineNuxtPlugin(() => { const token = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.tokenName, { - maxAge: 60 * 30, + maxAge: 60 * 5, }) const refreshToken = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.refreshTokenName, { maxAge: 60 * 60 * 24, @@ -80,6 +80,7 @@ export default defineNuxtPlugin(() => { 'refresh': refreshToken.value } }) + console.log('refresh', data, error) if (!error.value) { token.value = data.value.access }