Skip to content

requireCurrentUser ​

Overview ​

Require a successful answer to the current-user request, so the route can show or use the user object without requiring authentication.

Signature ​

requireCurrentUser(_router, pinia)

Parameters ​

NameTypeRequiredDescription
_routerRouteryesThe router instance.
piniaPiniayesThe Pinia instance.

Returns ​

Promise

Rejects with the request error when the current-user request fails, which rejects the navigation.

Examples ​

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

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/current-user-required/',
      name: 'current-user-required',
      component: () => import('@/views/ViewCurrentUserRequired.vue'),
      beforeEnter: (to, from) => requireCurrentUser(router, pinia),
    },
    // other routes
  ],
});

export default router;

Source ​

client/lib/router/guards.js:243