Skip to content

requireUnauth ​

Overview ​

Require the user to be unauthenticated, like for a login page.

Signature ​

requireUnauth(redirectTo, router, pinia)

Parameters ​

NameTypeRequiredDescription
redirectTostring | RouteLocationAsRelativeGeneric | RouteLocationAsPathGenericyesWhere to redirect if authenticated.
routerRouteryesThe router instance.
piniaPiniayesThe Pinia instance.

Returns ​

Promise

The redirect route if needed. Rejects with the request error when the current-user request fails, which rejects the navigation.

Examples ​

js
import { requireUnauth } from "@vueda/router/guards";
import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/unauth-required/',
      name: 'unauth-required',
      component: () => import('@/views/ViewUnauthRequired.vue'),
      beforeEnter: (to, from) => requireUnauth({ name: "welcome" }, router),
    },
    // other routes
  ],
});

export default router;

Source ​

client/lib/router/guards.js:207