better-auth organizations
When running
organizationCreationorganizationCreation's beforeCreate and afterCreate I don't see any request being passed in. It's only the organization details even though I am passing in the headers directly to the api (because I'm calling this from the server).// Organization plugin setup
organization({
// ... schema config omitted ...
organizationCreation: {
// This hook should receive req but you're saying it doesn't
beforeCreate: async ({ organization }, req) => {
const urlFriendlyName = organization.name
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.trim();
const randomString = generateRandomString(7);
return {
data: {
...organization,
slug: `${urlFriendlyName}-${randomString}`,
}
};
},
// This hook also should receive req but doesn't
afterCreate: async ({ organization, user }, req) => {
try {
const customer = await stripe.customers.create({
name: organization.name,
metadata: {
id: organization.id,
type: "organization",
slug: organization.slug,
},
});
// Missing session token here
await auth.api.updateOrganization({
body: {
headers: {
'firestorm-auth.session_token':
},
data: {
// @ts-expect-error This is specified in additionalFields
stripe_customer_id: customer.id,
},
organizationId: organization.id,
},
});
} catch (error) {
console.error("Error creating Stripe customer:", error);
auth.api.deleteOrganization({
headers: req?.headers, // req might be undefined
body: {
organizationId: organization.id,
},
});
}
},
},
}),// Organization plugin setup
organization({
// ... schema config omitted ...
organizationCreation: {
// This hook should receive req but you're saying it doesn't
beforeCreate: async ({ organization }, req) => {
const urlFriendlyName = organization.name
.toLowerCase()
.replace(/[^\w\s-]/g, "")
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.trim();
const randomString = generateRandomString(7);
return {
data: {
...organization,
slug: `${urlFriendlyName}-${randomString}`,
}
};
},
// This hook also should receive req but doesn't
afterCreate: async ({ organization, user }, req) => {
try {
const customer = await stripe.customers.create({
name: organization.name,
metadata: {
id: organization.id,
type: "organization",
slug: organization.slug,
},
});
// Missing session token here
await auth.api.updateOrganization({
body: {
headers: {
'firestorm-auth.session_token':
},
data: {
// @ts-expect-error This is specified in additionalFields
stripe_customer_id: customer.id,
},
organizationId: organization.id,
},
});
} catch (error) {
console.error("Error creating Stripe customer:", error);
auth.api.deleteOrganization({
headers: req?.headers, // req might be undefined
body: {
organizationId: organization.id,
},
});
}
},
},
}),