Update token handling and user state management

This commit is contained in:
wangqiao
2025-08-25 22:51:06 +08:00
parent 63fa551041
commit 7291768b03
5 changed files with 41 additions and 3 deletions

View File

@ -6,7 +6,8 @@ const useServerRequest = async <T>(
url: string,
opts?: UseFetchOptions<T, unknown>
) => {
const token = useCookie<string | undefined>("token");
const token = useToken();
const user = useUserInfo();
const runtimeConfig = useRuntimeConfig();
const defaultOptions: UseFetchOptions<unknown> = {
@ -14,9 +15,15 @@ const useServerRequest = async <T>(
onRequest({ options }) {
options.headers = options.headers || "application/json";
if (token.value) {
console.log('user----', user.value);
console.log('token----', "Bearer " + token.value)
// @ts-ignore
options.headers["authorization"] = "Bearer " + token.value;
}
console.log(url +'-----' +'options----', options);
},
onResponse({ response }) {
if (+response.status === 200 && +response._data.code !== 0) {