listAccounts()

I'm signed into an account in my app but listAccounts() is returning null unauthorized. Am I missing something that needs to be passed to listAccounts?
const accounts = await authClient.listAccounts();
// unauthorized
console.log("accounts in authentication form", accounts);
// this returns what I want
const authAccounts = await prisma.account.findMany({
where: {
userId: session.user.id,
},
});
const accounts = await authClient.listAccounts();
// unauthorized
console.log("accounts in authentication form", accounts);
// this returns what I want
const authAccounts = await prisma.account.findMany({
where: {
userId: session.user.id,
},
});
Solution:
Yeah, every authClient method is avalible in auth.api as well.
auth.api.listUserAccounts({headers: await headers()})
auth.api.listUserAccounts({headers: await headers()})
...
Jump to solution
6 Replies
Ping
Ping3mo ago
Are you calling authClient on the client side or server side?
iPheNoMeNaL-oG
iPheNoMeNaL-oGOP3mo ago
Ah calling it server side - guess Auth client won’t work is there a sever side call for it? Can’t find anything in docs
Solution
Ping
Ping3mo ago
Yeah, every authClient method is avalible in auth.api as well.
auth.api.listUserAccounts({headers: await headers()})
auth.api.listUserAccounts({headers: await headers()})
iPheNoMeNaL-oG
iPheNoMeNaL-oGOP3mo ago
Ah missed the listUserAccounts function was trying to call listAccounts with auth.api
Ping
Ping3mo ago
No worries! May I mark this as solved?
iPheNoMeNaL-oG
iPheNoMeNaL-oGOP3mo ago
Yes, thanks

Did you find this page helpful?