You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a microservices-based application where the frontend is in Next.js 15 (App Router), and user authentication is powered by NextAuth.js (v5, strategy: "jwt", credentials provider). The backend auth endpoints are handled by separate microservices.
Issue Description
After logging in via the credentials provider, the user is redirected to the / page (client-side navigation). However, the user session data (from useSession) is missing in all the client components (Navbar, PostCard, profile image hooks, etc.) until I manually reload the page.
On the initial navigation after login:
useSession returns null, so my custom hook (useGetUserData) throws “There is no user found”, causing runtime errors.
Only after a hard reload does the session data populate everywhere, and everything works fine.
This does not affect server components fetching session with auth(), only client-side hooks/components.
Implementation Details
Used official documentation and various community guides.
Session logic:
SessionProvider is wrapped at app root.
Credentials login handled with signIn("credentials", {redirect: false, ...}), then manually calling update() from useSession before redirecting to /.
Custom hooks depend on useSession for user data.
Microservice backend returns user object with tokens on successful login.
All relevant SessionProvider, hook and login logic is in accordance with docs.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi NextAuth team and community,
I'm building a microservices-based application where the frontend is in Next.js 15 (App Router), and user authentication is powered by NextAuth.js (v5, strategy: "jwt", credentials provider). The backend auth endpoints are handled by separate microservices.
Issue Description
After logging in via the credentials provider, the user is redirected to the / page (client-side navigation). However, the user session data (from useSession) is missing in all the client components (Navbar, PostCard, profile image hooks, etc.) until I manually reload the page.
On the initial navigation after login:
useSession returns null, so my custom hook (useGetUserData) throws “There is no user found”, causing runtime errors.
Only after a hard reload does the session data populate everywhere, and everything works fine.
This does not affect server components fetching session with auth(), only client-side hooks/components.
Implementation Details
Used official documentation and various community guides.
Session logic:
SessionProvider is wrapped at app root.
Credentials login handled with signIn("credentials", {redirect: false, ...}), then manually calling update() from useSession before redirecting to /.
Custom hooks depend on useSession for user data.
Microservice backend returns user object with tokens on successful login.
All relevant SessionProvider, hook and login logic is in accordance with docs.
Loging Logic:
`const onSubmit = async (data: SignInSchema) => {
try {
// Use NextAuth signIn
const result = (await signIn("credentials", {
redirect: false,
email: data.email,
password: data.password,
})) as { error?: string };
"use client";
import { useSession } from "next-auth/react";
export default function useGetUserData() {
const { data: session, status } = useSession();
if (status === "loading") {
return null; // or return loading state
}
}
return session.user;
}
`
Beta Was this translation helpful? Give feedback.
All reactions