can't get session after verify magic link token

React.useEffect(() => {
const handleTokenVerification = async (token: string) => {
const { error, data } = await verifyToken(token);

if (data) {
console.log({ data });

// Force a fresh session check after successful verification
const freshSession = await getSession();
if (freshSession) {
session.refetch();
}
} else if (error?.status === 0) {
setError(true);
}
};

if (token && !session.data && !session.isPending) {
handleTokenVerification(token);
}
}, [token, session]);
React.useEffect(() => {
const handleTokenVerification = async (token: string) => {
const { error, data } = await verifyToken(token);

if (data) {
console.log({ data });

// Force a fresh session check after successful verification
const freshSession = await getSession();
if (freshSession) {
session.refetch();
}
} else if (error?.status === 0) {
setError(true);
}
};

if (token && !session.data && !session.isPending) {
handleTokenVerification(token);
}
}, [token, session]);
this is my config. the console.log shows that I get the data, but when i try to getSession or refetch.session, it always return null. Im using bun as runner
4 Replies
SkepticMystic
SkepticMystic4d ago
I usually find that doing a hard reload triggers the session. Sometimes there's a less intense way of refreshing, but that seems to be a fail-safe
Salma
SalmaOP4d ago
I tried that, and checked the network, getSession kept returning null I integrate better-auth with Hono
SkepticMystic
SkepticMystic4d ago
Don't use getSession, the hard refresh will reload the session hook for you
Salma
SalmaOP4d ago
same issue. I wonder if its db configuration issue. because const { error, data } = await verifyToken(token); return the session, but it somehow not set the current session

Did you find this page helpful?