2
0

feat: 🚩 Add webhook url call on user creation

This commit is contained in:
Baptiste Arnaud
2022-03-23 15:47:53 +01:00
parent 953b95d254
commit 39b01431e0
2 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import { PrismaClient, Prisma, Invitation, Plan } from 'db'
import { randomUUID } from 'crypto' import { randomUUID } from 'crypto'
import type { Adapter, AdapterUser } from 'next-auth/adapters' import type { Adapter, AdapterUser } from 'next-auth/adapters'
import cuid from 'cuid' import cuid from 'cuid'
import { got } from 'got'
export function CustomAdapter(p: PrismaClient): Adapter { export function CustomAdapter(p: PrismaClient): Adapter {
return { return {
@ -19,6 +20,10 @@ export function CustomAdapter(p: PrismaClient): Adapter {
plan: process.env.ADMIN_EMAIL === data.email ? Plan.PRO : Plan.FREE, plan: process.env.ADMIN_EMAIL === data.email ? Plan.PRO : Plan.FREE,
}, },
}) })
if (process.env.USER_CREATED_WEBHOOK_URL)
await got.post(process.env.USER_CREATED_WEBHOOK_URL, {
json: data,
})
if (invitations.length > 0) if (invitations.length > 0)
await convertInvitationsToCollaborations(p, user, invitations) await convertInvitationsToCollaborations(p, user, invitations)
return createdUser return createdUser

View File

@ -181,3 +181,12 @@ These can also be added to the `viewer` environment
| SLEEKPLAN_SSO_KEY | -- | Sleekplan SSO key used to automatically authenticate a user in Sleekplan | | SLEEKPLAN_SSO_KEY | -- | Sleekplan SSO key used to automatically authenticate a user in Sleekplan |
</p></details> </p></details>
<details><summary>Webhooks</summary>
<p>
| Parameter | Default | Description |
| ------------------------ | ------- | --------------------------------------------------------------------------------------------- |
| USER_CREATED_WEBHOOK_URL | -- | Webhook URL called whenever a new user is created (used for importing a new SendGrid contact) |
</p></details>