From 5c5b35b1b5626f5f52722f10b4f75fc82aa00cfd Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 26 Sep 2025 01:11:58 +0800 Subject: [PATCH] :bug: Fix authorization --- app/composables/useSolarNetwork.ts | 7 ++++++- app/pages/auth/authorize.vue | 2 +- app/plugins/01.auth.ts | 24 ++++++++++++++++++++++++ app/stores/user.ts | 5 +---- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 app/plugins/01.auth.ts diff --git a/app/composables/useSolarNetwork.ts b/app/composables/useSolarNetwork.ts index b30f85f..76a7c6c 100644 --- a/app/composables/useSolarNetwork.ts +++ b/app/composables/useSolarNetwork.ts @@ -8,12 +8,15 @@ export const useSolarNetwork = (withoutProxy = false) => { baseURL: apiBase, credentials: "include", // Add Authorization header with Bearer token - onRequest: ({ options }) => { + onRequest: ({ request, options }) => { + const side = process.server ? 'SERVER' : 'CLIENT' + console.log(`[useSolarNetwork] onRequest for ${request} on ${side}`) // Get token from user store const userStore = useUserStore() const token = userStore.token if (token) { + console.log('[useSolarNetwork] Token found, adding Authorization header.') if (!options.headers) { options.headers = new Headers() } @@ -23,6 +26,8 @@ export const useSolarNetwork = (withoutProxy = false) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any ;(options.headers as any)["Authorization"] = `Bearer ${token}` } + } else { + console.log('[useSolarNetwork] No token found, skipping Authorization header.') } // Transform request data from camelCase to snake_case diff --git a/app/pages/auth/authorize.vue b/app/pages/auth/authorize.vue index 1f3d6c2..cae3cde 100644 --- a/app/pages/auth/authorize.vue +++ b/app/pages/auth/authorize.vue @@ -53,7 +53,7 @@

This will allow - {{ clientInfo.clientName || "the app" }} to: + {{ clientInfo.clientName || "the app" }} to