From 836df995d0a661e8f873a0caf6e5b6449a51acf8 Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 3 Apr 2023 22:04:52 +0800 Subject: [PATCH] Improve login and authentication methods to adapt to the SSR mode. --- components/Conversation.vue | 2 +- composables/useAuthFetch.js | 5 ++--- layouts/default.vue | 4 ++-- middleware/auth.ts | 12 ++++++++---- pages/account/onboarding.vue | 3 ++- pages/account/resetPassword.vue | 3 +-- pages/account/signin.vue | 1 - pages/account/signup.vue | 4 +--- utils/helper.js | 15 +++++++-------- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/components/Conversation.vue b/components/Conversation.vue index 81c8043..e8f050e 100644 --- a/components/Conversation.vue +++ b/components/Conversation.vue @@ -2,7 +2,7 @@ import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source' import {addConversation} from "../utils/helper"; -const { $i18n, $auth } = useNuxtApp() +const { $i18n } = useNuxtApp() const runtimeConfig = useRuntimeConfig() const currentModel = useCurrentModel() const openaiApiKey = useApiKey() diff --git a/composables/useAuthFetch.js b/composables/useAuthFetch.js index 72e7d40..a1acd12 100644 --- a/composables/useAuthFetch.js +++ b/composables/useAuthFetch.js @@ -1,9 +1,8 @@ -export const useAuthFetch = async (url, options = {}) => { - const { $auth } = useNuxtApp() +export const useAuthFetch = async (url, options = {}) => { const res = await useFetch(url, options) if (res.error.value && res.error.value.status === 401) { - await $auth.logout() + await logout() } return res } diff --git a/layouts/default.vue b/layouts/default.vue index 22b6f0e..e56ff2e 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -1,7 +1,7 @@