[Urgent] Not getting custom session while using apikey
I have a custom session setup that works perfectly with traditional logins, but when I use an API key, I get the default key-values of the session object
1 Reply
server/auth.ts
lib/authClient.ts
const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
schema: {
...authSchema,
},
}),
...
plugins: [
apiKey(),
username(),
nextCookies(),
admin(),
customSession(async ({ user, session }) => {
/// fetch some data
return {
user: {
...user,
role: data?.role, // extra
watchExpiration: data?.watchExpiration,// extra
watchCreatedAt: data?.watchCreatedAt,// extra
apiKeyId: data?.apiKeyId,// extra
},
session,
};
}),
],
});
const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
schema: {
...authSchema,
},
}),
...
plugins: [
apiKey(),
username(),
nextCookies(),
admin(),
customSession(async ({ user, session }) => {
/// fetch some data
return {
user: {
...user,
role: data?.role, // extra
watchExpiration: data?.watchExpiration,// extra
watchCreatedAt: data?.watchCreatedAt,// extra
apiKeyId: data?.apiKeyId,// extra
},
session,
};
}),
],
});
const authClient = createAuthClient({
baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
plugins: [
usernameClient(),
adminClient(),
apiKeyClient(),
customSessionClient<typeof auth>(),
],
});
const authClient = createAuthClient({
baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
plugins: [
usernameClient(),
adminClient(),
apiKeyClient(),
customSessionClient<typeof auth>(),
],
});