Update token handling and user state management
This commit is contained in:
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user