🐛 Fix the authorize page

This commit is contained in:
2025-09-30 01:04:20 +08:00
parent 888d3cb5ba
commit 98a5d34f3c
6 changed files with 2895 additions and 30 deletions

View File

@@ -9,14 +9,16 @@ export const useSolarNetwork = (withoutProxy = false) => {
credentials: "include",
// Add Authorization header with Bearer token
onRequest: ({ request, options }) => {
const side = process.server ? 'SERVER' : 'CLIENT'
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.')
console.log(
"[useSolarNetwork] Token found, adding Authorization header."
)
if (!options.headers) {
options.headers = new Headers()
}
@@ -27,7 +29,9 @@ export const useSolarNetwork = (withoutProxy = false) => {
;(options.headers as any)["Authorization"] = `Bearer ${token}`
}
} else {
console.log('[useSolarNetwork] No token found, skipping Authorization header.')
console.log(
"[useSolarNetwork] No token found, skipping Authorization header."
)
}
// Transform request data from camelCase to snake_case
@@ -46,5 +50,5 @@ export const useSolarNetwork = (withoutProxy = false) => {
export const useSolarNetworkUrl = (withoutProxy = false) => {
const config = useRuntimeConfig()
return (config.public.development && !withoutProxy) ? "/api" : config.public.apiBase
return config.public.apiBase
}