Skip to content

requireAuth

Overview

Require the user to be authenticated.

Signature

requireAuth(redirectTo, to, router, pinia)

Parameters

NameTypeRequiredDescription
redirectTostring | RouteLocationAsRelativeGeneric | RouteLocationAsPathGenericyesWhere to redirect if not authenticated.
toRouteLocationNormalizedGenericyesThe target route.
routerRouteryesThe router instance.
piniaPiniayesThe Pinia instance.

Returns

Promise

The redirect route if needed.

Examples

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

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

export default router;

Source

client/lib/router/guards.js:108

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2