change in progress

This commit is contained in:
Emily
2024-10-02 17:05:34 +02:00
parent f516c53b7b
commit 314660d8a3
22 changed files with 503 additions and 438 deletions

View File

@@ -1,9 +1,8 @@
const ACCESS_TOKEN_STATE_KEY = 'access_token';
const ACCESS_TOKEN_COOKIE_KEY = 'access_token';
const tokenCookie = useCookie(ACCESS_TOKEN_COOKIE_KEY, { expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30) });
const token = ref<string | undefined>();
export function signHeaders(headers?: Record<string, string>) {
const { token } = useAccessToken()
@@ -15,26 +14,12 @@ export const authorizationHeaderComputed = computed(() => {
return token.value ? 'Bearer ' + token.value : '';
});
function setToken(value: string) {
tokenCookie.value = value;
token.value = value;
}
export function useAccessToken() {
const tokenCookie = useCookie(ACCESS_TOKEN_COOKIE_KEY, { expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30) })
const token = useState<string | undefined | null>(ACCESS_TOKEN_STATE_KEY);
const needLoad = useState<boolean>('needAccessTokenLoad', () => true);
const readToken = () => {
token.value = tokenCookie.value;
needLoad.value = false;
}
const setToken = (newToken: string) => {
tokenCookie.value = newToken;
token.value = tokenCookie.value;
needLoad.value = false;
}
if (needLoad.value == true) readToken();
return { token, readToken, setToken, needLoad }
if (!token.value) token.value = tokenCookie.value as any;
return { setToken, token }
}