impersonatedBy missing in admin session

I am using the admin plugin for impersonation. When i get the current data with auth.api.getSession(), the TypeScript type for the session does not include the impersonatedBy field, so when I try to access it for conditional rendering I get a TS error. At runtime it works correctly, and the impersonatedBy field is present in the JS session object as null or with the correct ID. How can I make my auth instance aware I am using the admin plugin so it knows impersonatedBy is in the session object?
Solution:
Hello, types should had inferred correctly if you're using auth.api and have included the admin plugin. May I see the useAuth hook? @chris...
No description
Jump to solution
5 Replies
chris
chrisOP5mo ago
const hub = await auth.api.getSession({
headers: awaited
})
const hub = await auth.api.getSession({
headers: awaited
})
No description
chris
chrisOP5mo ago
Property 'impersonatedBy' does not exist on type '{ id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }'
Solution
Ping
Ping5mo ago
Hello, types should had inferred correctly if you're using auth.api and have included the admin plugin. May I see the useAuth hook? @chris
No description
Ping
Ping5mo ago
On an unrelated note, if useAuth is a hook don't forget to include "use client" in your file 😁
chris
chrisOP5mo ago
yes, once i inferred the type of session from auth.api it worked correctly, thank you @Ping

Did you find this page helpful?