I created a Next.js 15 project using AWS Amplify Gen 2. After logging in, I can successfully fetch and display user-related data (e.g., offers).
However, if I refresh the page or navigate away and return, the app fails to fetch the offers. Upon debugging, I noticed that the user object becomes undefined, causing all authenticated requests to fail.
This issue happens across all pages after login. It seems like the authenticated user information is lost on refresh or navigation.
Why is this happening, and how can I ensure the user stays authenticated across page reloads? It is in sandbox env.
Here’s an example of my offers/page.tsx code:
"use client";
import { useEffect, useState } from "react";
import { generateClient } from "aws-amplify/data";
import type { Schema } from "@/amplify/data/resource";
import { Authenticator, useAuthenticator } from "@aws-amplify/ui-react";
import { useRouter } from "next/navigation";
import { Auth } from "aws-amplify";
const client = generateClient<Schema>();
function AuthDebugger() {
const [authUser, setAuthUser] = useState(null);
useEffect(() => {
const checkAuth = async () => {
try {
console.log("