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

# requireRecentAuth

## Overview

Require the user to be recently authenticated: signed in with no `storeUser.authPendingFlow`. When the store
has no successful answer to the current-user request yet, the guard waits for one. When the store already
holds a recent session, the guard refetches the current user, so an expired session is caught here.

## Signature

`requireRecentAuth(redirectTo, to, router, pinia)`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| <span id="param-redirectTo">redirectTo</span> | `string \| RouteLocationAsRelativeGeneric \| RouteLocationAsPathGeneric` | yes | Where to redirect if not recently authenticated. |
| <span id="param-to">to</span> | `RouteLocationNormalizedGeneric` | yes | The target route. |
| <span id="param-router">router</span> | `Router` | yes | The router instance. |
| <span id="param-pinia">pinia</span> | `Pinia` | yes | The 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 { requireRecentAuth } from "@vueda/router/guards";
import { createRouter } from "vue-router";

const router = createRouter({
  routes: [
    {
      path: "/:app/:model/setup",
      name: "setup-device",
      component: () => import('@/views/ViewAuthRequired.vue'),
      beforeEnter: (to, from) => requireRecentAuth({ name: "reauthenticate" }, to, router),
    },
    // other routes
  ],
});

export default router;
```

## Source

`client/lib/router/guards.js:164`
