trouble with organization creation in the afterEmailVerification callback

Hi everyone! I'm trying create an organization automatically when a user verifies their email using the afterEmailVerification callback.
import { headers } from 'next/headers'
afterEmailVerification: async (user, request) => {
try {
const organization = await auth.api.createOrganization({
body: {
name: user.email,
slug: generateOrganizationSlug(),
logo: getOrganizationLogo(),
userId: user.id,
keepCurrentActiveOrganization: true,
},
headers: await headers(),
})
console.log(`Organization created: ${organization}`)
} catch (error) {
console.error('Failed to create organization:', error)
}
}
import { headers } from 'next/headers'
afterEmailVerification: async (user, request) => {
try {
const organization = await auth.api.createOrganization({
body: {
name: user.email,
slug: generateOrganizationSlug(),
logo: getOrganizationLogo(),
userId: user.id,
keepCurrentActiveOrganization: true,
},
headers: await headers(),
})
console.log(`Organization created: ${organization}`)
} catch (error) {
console.error('Failed to create organization:', error)
}
}
I have tried headers: request.headers and without header still no luck. Im getting error Failed to create organization: [Error [APIError]: ] { status: 'UNAUTHORIZED', body: undefined, headers: {}, statusCode: 401 }
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?