# Logged out when refreshing

**URL:** <https://community.auth0.com/t/logged-out-when-refreshing/155516>\
**Category:** Get Help\
**Tags:** free-trial, login-experience\
**Created:** [November 29, 2024, 4:08pm UTC](https://community.auth0.com/t/logged-out-when-refreshing/155516 "2024-11-29T16:08:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TwistedBird](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/twistedbird/32/59979_2.png) [@TwistedBird](https://community.auth0.com/u/TwistedBird)\
**Post date:** [November 29, 2024, 4:08pm UTC](https://community.auth0.com/t/logged-out-when-refreshing/155516/1 "2024-11-29T16:08:10Z")

</div>

I am using Auth0 with a NextJS app hosted in Google Cloud. My middleware file currently looks like this:

> import { withMiddlewareAuthRequired } from “@auth0/nextjs-auth0/edge”;  
> import { NextResponse } from “next/server”;  
> import type { NextRequest } from “next/server”;
> 
> export default withMiddlewareAuthRequired({  
> async middleware(req: NextRequest) {  
> const response = NextResponse.next();
> 
> ```
> response.headers.set("X-Content-Type-Options", "nosniff");
> 
> return response;
> 
> ```
> 
> },  
> });

When running it locally, I am asked to login once the first time I visit the page, then not asked again unless I log out. However, when using the version in Google Cloud Run, I am asked to login again every time I refresh the page or am loading a page that triggers a server action that sends a request to an API I am yet to contact in this session. Essentially, it has to log in again every time I refresh or contact a new API, but this does not happen locally. Are there any specific configuration issues within Auth0 related to Google Cloud and/or NextJS I might have missed?

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [November 29, 2024, 6:50pm UTC](https://community.auth0.com/t/logged-out-when-refreshing/155516/2 "2024-11-29T18:50:33Z")

</div>

Hi @TwistedBird

Welcome to the Auth0 Community!

There are a couple of different causes that may be resulting in your application losing authentication after the page refreshes. This article explains the two most common reasons (developer keys & blocked third-party cookies)

[https://community.auth0.com/t/why-is-authentication-lost-after-refreshing-my-single-page-application/56276](https://community.auth0.com/t/why-is-authentication-lost-after-refreshing-my-single-page-application/56276)

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 13, 2024, 6:51pm UTC](https://community.auth0.com/t/logged-out-when-refreshing/155516/3 "2024-12-13T18:51:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
