useSession returns null for data in Next.js

Client side useSession form Better-Auth Client returns null:
const { data, error, refetch, isPending } = useSession();
console.log("SESSION DATA: ", data);
// logs SESSION DATA: null
const { data, error, refetch, isPending } = useSession();
console.log("SESSION DATA: ", data);
// logs SESSION DATA: null
Have no idea why. Can someone help me to figure it out? Does anyone had such issue?
Solution:
Are you sure the data isn't just pending? Because while it's pending you will get null.
Jump to solution
4 Replies
Glen Kurio
Glen KurioOP11h ago
I set nextCookies plugin in BA Config as a last one in the array of plugins And I import createAuthClient from the right place:
import { createAuthClient } from "better-auth/react";
import { createAuthClient } from "better-auth/react";
Could you help, please ? @Ping
Solution
Ping
Ping11h ago
Are you sure the data isn't just pending? Because while it's pending you will get null.
The Untraceable
The Untraceable11h ago
How have you setup your auth.ts and auth-client? Are you sure you're logged in?
Glen Kurio
Glen KurioOP11h ago
That's it. 🤦‍♂️ Thank you

Did you find this page helpful?