---
url: "https://vueda.dev/v3/reference/api/js/router/guards/functions/requireCurrentUser.md"
title: "requireCurrentUser"
---

# 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

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| <span id="param-_router">_router</span> | `Router` | yes | The router instance. |
| <span id="param-pinia">pinia</span> | `Pinia` | yes | The 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`
