Conflict between Admin and Anonymous plugins – 500 error

Hello, I'm having an issue with two plugins: Admin and Anonymous. When I try to use Anonymous while the Admin plugin is enabled, I get a 500 error. However, if I disable the Admin plugin, Anonymous works perfectly. Is there a specific configuration I need to set up? Or are these two plugins simply not compatible with each other? I haven’t found anything about this in the documentation or the issues section. If anyone has any idea, I’d really appreciate the help! Thanks in advance 😊
No description
7 Replies
bekacru
bekacru4w ago
I couldn't reproduce it on my end. Could you send me your auth config?
Al.exe
Al.exeOP4w ago
Yes, of course, in auth.ts:
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: 'postgresql'
}),
user: {
additionalFields: {
role: {
type: 'string'
},
plan: {
type: 'string'
}
}
},
socialProviders: {
// --- Google
},
plugins: [
magicLink({
sendMagicLink: async ({ email, url }) => {
// --- Send email
}
}),
stripe({
stripeClient,
stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET,
createCustomerOnSignUp: true,
subscription: {}
}),
/*anonymous({
emailDomainName: env.RESEND_DOMAIN
}),*/
customSession(async ({ user, session }) => {
// --- Fetch User ---
const userNew = await prisma.user.findUnique({
where: {
id: user.id
}
})

// --- Return ---
return {
session,
user: {
...user,
...userNew
}
}
}),
admin()
]
})
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: 'postgresql'
}),
user: {
additionalFields: {
role: {
type: 'string'
},
plan: {
type: 'string'
}
}
},
socialProviders: {
// --- Google
},
plugins: [
magicLink({
sendMagicLink: async ({ email, url }) => {
// --- Send email
}
}),
stripe({
stripeClient,
stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET,
createCustomerOnSignUp: true,
subscription: {}
}),
/*anonymous({
emailDomainName: env.RESEND_DOMAIN
}),*/
customSession(async ({ user, session }) => {
// --- Fetch User ---
const userNew = await prisma.user.findUnique({
where: {
id: user.id
}
})

// --- Return ---
return {
session,
user: {
...user,
...userNew
}
}
}),
admin()
]
})
and in authClient:
import {
magicLinkClient,
customSessionClient,
//anonymousClient,
adminClient
} from 'better-auth/client/plugins'

// --- Auth Client ---
export const authClient = createAuthClient({
plugins: [
magicLinkClient(),
//anonymousClient(),
customSessionClient<typeof auth>(),
stripeClient({
subscription: true
}),
adminClient()
]
})
import {
magicLinkClient,
customSessionClient,
//anonymousClient,
adminClient
} from 'better-auth/client/plugins'

// --- Auth Client ---
export const authClient = createAuthClient({
plugins: [
magicLinkClient(),
//anonymousClient(),
customSessionClient<typeof auth>(),
stripeClient({
subscription: true
}),
adminClient()
]
})
For the moment they are commented And I call it in the layout:
/*
'use client'

// --- Dependencies ---
import { useEffect } from 'react'
import { signIn, authClient } from '@/lib/auth-client'*/

// --- Components: Layout ---
import Header from '@/components/layout/header'
import Footer from '@/components/layout/footer'

// --- Layout:Space ---
export default function HomeLayout({
children
}: Readonly<{ children: React.ReactNode }>) {
/*useEffect(() => {
;(async () => {
const { data, error } = await signIn.anonymous()
console.log('DATA', data)
console.log('ERROR', error)
})()
}, [])*/

// --- Render ---
return (
<div className="relative w-full overflow-x-hidden">
<Header />
<div className="pt-14">{children}</div>
<Footer />
</div>
)
}
/*
'use client'

// --- Dependencies ---
import { useEffect } from 'react'
import { signIn, authClient } from '@/lib/auth-client'*/

// --- Components: Layout ---
import Header from '@/components/layout/header'
import Footer from '@/components/layout/footer'

// --- Layout:Space ---
export default function HomeLayout({
children
}: Readonly<{ children: React.ReactNode }>) {
/*useEffect(() => {
;(async () => {
const { data, error } = await signIn.anonymous()
console.log('DATA', data)
console.log('ERROR', error)
})()
}, [])*/

// --- Render ---
return (
<div className="relative w-full overflow-x-hidden">
<Header />
<div className="pt-14">{children}</div>
<Footer />
</div>
)
}
bekacru
bekacru4w ago
so anonymous plugin doesn't work when the admin plugin is mounted. is that the case? also are you on latest?
Al.exe
Al.exeOP4w ago
Yes, exactly, it gives me a error 500, and I'm on the "better-auth" version: "^1.2.5"
No description
bekacru
bekacru4w ago
hmm couldn't reproduce it in my end. If you could send me a poc, would happy to take a look.
Al.exe
Al.exeOP4w ago
I started a project from scratch
KHRM
KHRM2w ago
do we need to add the addiitonalFields role if we are using the admin plugin

Did you find this page helpful?