import { ref } from 'vue' // Token Service // // 設計重點: // - 單一來源(Single Source of Truth):用 ref 維護 token,並同步 localStorage // - Store 與 Interceptor 只透過此 service 讀寫 token,避免來源分裂 const storageKey = 'token' const tokenRef = ref(localStorage.getItem(storageKey)) export const tokenService = { token: tokenRef, getToken() { return tokenRef.value }, setToken(nextToken: string) { tokenRef.value = nextToken localStorage.setItem(storageKey, nextToken) }, clearToken() { tokenRef.value = null localStorage.removeItem(storageKey) }, }