Unable to get user information using useSession hooke #11318
Unanswered
Nishan211775
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Provider type
Identity Server 4
Environment
System:
OS: Windows 11 10.0.22621
CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
Memory: 2.50 GB / 15.79 GB
Binaries:
Node: 20.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (126.0.2592.81)
Internet Explorer: 11.0.22621.3527
npmPackages:
next: 14.2.3 => 14.2.3
next-auth: ^4.24.7 => 4.24.7
react: ^18 => 18.3.1
Reproduction URL
https://github.com/Nishan211775/next-js
Describe the issue
I am using Identity Server as a provider for authentication. I want to get user information on my Next.js pages using the useSession hooks. After a successful login, I am able to get the user details and access token using the useSession hooks. However, the problem arises when I move away from my application, open another application or tab, and then return to my application and refresh the page. At this point, the user details and access token become null. I discovered that if I move away from my application's browser, it triggers the callback function that I have configured in my nextauth.js configuration, where the user information and access token are null. Note that I have added the required claims from the backend (i.e., the Identity Server application).
If I log in to the application, it will trigger the callback function where I can get the user information and access token. After redirecting to the pages, it will return the user information. However, after moving away from the application, it will again trigger the callback function, and this time the user information becomes null.
NOTE: Refreshing the page also will not give the user information
This is the [...nextauth.js]
on my next page i have use useSession hook like this
const { data: session } = useSession();
How to reproduce
Step to reproduct.
Expected behavior
Should able to retrieve the user information and access token using useSession hook
Beta Was this translation helpful? Give feedback.
All reactions