import type { NavigationGuard } from 'vue-router';
import { getPinia, useAccountStore } from '@/stores';

export const accountGuard: NavigationGuard = (to) => {
  if (!to.meta.account) return;
  if (to.name === 'forbidden') return;

  const { token } = useAccountStore(getPinia());
  if (token) return;

  return { name: 'forbidden', replace: true, query: { redirect: to.fullPath } };
};
