Fixes: 1) Reorder `router.push` in `useLogout` to properly clear cookies before redirection; 2) Resolve issues with inconsistent access token handling during Apollo header configuration; Extra: 1) Cleanup comments in `useRefresh
36 lines
No EOL
686 B
TypeScript
36 lines
No EOL
686 B
TypeScript
import {useAppConfig} from "~/composables/config";
|
|
|
|
export function useLogout() {
|
|
const userStore = useUserStore();
|
|
const router = useRouter();
|
|
|
|
const { COOKIES_REFRESH_TOKEN_KEY, COOKIES_ACCESS_TOKEN_KEY } = useAppConfig();
|
|
|
|
const cookieRefresh = useCookie(
|
|
COOKIES_REFRESH_TOKEN_KEY,
|
|
{
|
|
default: () => '',
|
|
path: '/'
|
|
}
|
|
);
|
|
const cookieAccess = useCookie(
|
|
COOKIES_ACCESS_TOKEN_KEY,
|
|
{
|
|
default: () => '',
|
|
path: '/'
|
|
}
|
|
);
|
|
|
|
async function logout() {
|
|
await router.push({path: '/'});
|
|
|
|
userStore.setUser(null);
|
|
|
|
cookieRefresh.value = '';
|
|
cookieAccess.value = '';
|
|
}
|
|
|
|
return {
|
|
logout
|
|
};
|
|
} |