BA
Better Auth•4mo ago
Emi

getSession is not returning userAgent

I've been trying to set up a multisession feature so users can revoke access on other devices session. But getSession it not returning userAgent nor ipAddress. I even followed the Better Auth report example.
Solution:
Yeah, I create a server action and passed the headers when calling the function. ```export const getSessionData = async () => { try { const headersList = await headers(); ...
Jump to solution
5 Replies
iatomic.btc
iatomic.btc•4mo ago
Hey @Emi have u been able to fix this?
Rodrigo Santos
Rodrigo Santos•4mo ago
Hi @Emi could you provide some insights and some code of where you are using getSession() ? getSession is meant to be used on the client side. I suspect that you might be using the getSession the server
No description
Solution
Emi
Emi•4mo ago
Yeah, I create a server action and passed the headers when calling the function.
export const getSessionData = async () => {
try {
const headersList = await headers();

const [session, activeSessions] = await Promise.all([
auth.api.getSession({ headers: headersList }),
auth.api.listSessions({ headers: headersList }),
]);

return {
session,
activeSessions,
isAuthenticated: !!session,
};
} catch (error) {
console.error("Error in getSessionData:", error);
return {
session: null,
activeSessions: [],
isAuthenticated: false,
};
}
};
export const getSessionData = async () => {
try {
const headersList = await headers();

const [session, activeSessions] = await Promise.all([
auth.api.getSession({ headers: headersList }),
auth.api.listSessions({ headers: headersList }),
]);

return {
session,
activeSessions,
isAuthenticated: !!session,
};
} catch (error) {
console.error("Error in getSessionData:", error);
return {
session: null,
activeSessions: [],
isAuthenticated: false,
};
}
};
Emi
EmiOP•4mo ago
I wanted to use the server side instead
Rodrigo Santos
Rodrigo Santos•4mo ago
Nice 🙂

Did you find this page helpful?