♻️ Refactored the auth flow

This commit is contained in:
2025-10-01 22:52:23 +08:00
parent 3e68158b4e
commit 6853acea98
4 changed files with 23 additions and 63 deletions

View File

@@ -11,28 +11,6 @@ export const useSolarNetwork = (withoutProxy = false) => {
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()
}
if (options.headers instanceof Headers) {
options.headers.set("Authorization", `Bearer ${token}`)
} else {
// 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
if (options.body && typeof options.body === "object") {