export default defineNuxtRouteMiddleware( async (to, from) => {
await useUserQueryAuth();
if (useUserStore().isGuest && to.path !== '/user/auth/login') {
return navigateTo('/user/auth/login');
}
if (!useUserStore().isGuest && to.path === '/user/auth/login') {
return navigateTo('/');
}
});
/**
* @inheritdoc
*/
public function behaviors()
{
$behaviors = parent::behaviors();
unset($behaviors['authenticator']);
// Добавляем первоначально CORS!
$behaviors['corsFilter'] = [
'class' => Cors::class,
];
// Теперь авторизацию.
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::class,
'except' => ['options'],
];
return $behaviors;
}