# How to redirect users to landing page, as soon as session has expired?

**URL:** <https://community.auth0.com/t/how-to-redirect-users-to-landing-page-as-soon-as-session-has-expired/190187>\
**Category:** Get Help\
**Tags:** sessions, access-token\
**Created:** [August 5, 2025, 6:47pm UTC](https://community.auth0.com/t/how-to-redirect-users-to-landing-page-as-soon-as-session-has-expired/190187 "2025-08-05T18:47:51Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [August 6, 2025, 4:41pm UTC](https://community.auth0.com/t/how-to-redirect-users-to-landing-page-as-soon-as-session-has-expired/190187/3 "2025-08-06T16:41:06Z")

</div>

Hi @brodanoel,

Welcome to the Auth0 Community!

You can redirect the users when using the NextJS SDK from the middleware using a code snippet described in our [nextjs-auth0 /EXAMPLES.md](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#session-configuration) github page such as this:

```auto
const session = await auth0.getSession(request);

  if (!session) {
    // user is not authenticated, redirect to login page
    return NextResponse.redirect(
      new URL("/auth/login", request.nextUrl.origin)
    );
  }

```

It is not recommended to expose the access token on the frontend, but another method would be decoding it in your backend, and based on the `exp` claim you can determine when the access token is close to expire. You can check out [this community post](https://community.auth0.com/t/how-to-check-access-token-is-expired/78890) or [this one](https://community.auth0.com/t/change-expiration-time-of-access-token/125726/3), then pass this information to your frontend.

I hope this helps, and if you have further questions please let me know!  
Best regards,  
Remus

---

_[View the full topic](https://community.auth0.com/t/how-to-redirect-users-to-landing-page-as-soon-as-session-has-expired/190187)._
