feat(api): add clerk webhook logging
Some checks failed
Build and Push Docker Image / tests (push) Failing after 56s
Build and Push Docker Image / build (push) Has been skipped

This commit is contained in:
Lars Hampe 2024-10-02 15:24:38 +02:00
parent 30b0a1c584
commit 3535b97cfa
4 changed files with 9 additions and 2 deletions

View File

@ -8,6 +8,7 @@
"dependencies": { "dependencies": {
"@boring.tools/database": "workspace:*", "@boring.tools/database": "workspace:*",
"@boring.tools/schema": "workspace:*", "@boring.tools/schema": "workspace:*",
"@boring.tools/logger": "workspace:*",
"@hono/clerk-auth": "^2.0.0", "@hono/clerk-auth": "^2.0.0",
"@hono/zod-openapi": "^0.16.2", "@hono/zod-openapi": "^0.16.2",
"@scalar/hono-api-reference": "^0.5.149", "@scalar/hono-api-reference": "^0.5.149",

View File

@ -1,3 +1,4 @@
import { logger } from '@boring.tools/logger'
import { OpenAPIHono } from '@hono/zod-openapi' import { OpenAPIHono } from '@hono/zod-openapi'
import { HTTPException } from 'hono/http-exception' import { HTTPException } from 'hono/http-exception'
import { Webhook } from 'svix' import { Webhook } from 'svix'
@ -27,8 +28,10 @@ app.openapi(webhook.route, async (c) => {
const headers = c.req.header() const headers = c.req.header()
const verifiedPayload = wh.verify(JSON.stringify(payload), headers) const verifiedPayload = wh.verify(JSON.stringify(payload), headers)
const result = await webhook.func({ payload: verifiedPayload }) const result = await webhook.func({ payload: verifiedPayload })
logger.info('Clerk Webhook', result)
return c.json(result, 200) return c.json(result, 200)
} catch (error) { } catch (error) {
logger.error('Clert Webhook', error)
if (error instanceof HTTPException) { if (error instanceof HTTPException) {
return c.json({ message: error.message }, error.status) return c.json({ message: error.message }, error.status)
} }

View File

@ -1,4 +1,5 @@
import { migrateDatabase } from '@boring.tools/database' import { migrateDatabase } from '@boring.tools/database'
import { logger } from '@boring.tools/logger'
declare module 'bun' { declare module 'bun' {
interface Env { interface Env {
@ -12,7 +13,7 @@ declare module 'bun' {
export const startup = async () => { export const startup = async () => {
if (import.meta.env.NODE_ENV === 'test') { if (import.meta.env.NODE_ENV === 'test') {
if (!import.meta.env.POSTGRES_URL) { if (!import.meta.env.POSTGRES_URL) {
console.error('Env Var POSTGRES_URL is missing!') logger.error('Env Var POSTGRES_URL is missing!')
process.exit(0) process.exit(0)
} }
return return
@ -25,7 +26,7 @@ export const startup = async () => {
] ]
keys.map((key) => { keys.map((key) => {
if (!import.meta.env[key]) { if (!import.meta.env[key]) {
console.error(`Env Var ${key} is missing!`) logger.error(`Env Var ${key} is missing!`)
process.exit(0) process.exit(0)
} }
}) })
@ -33,4 +34,6 @@ export const startup = async () => {
if (import.meta.env.NODE_ENV === 'production') { if (import.meta.env.NODE_ENV === 'production') {
await migrateDatabase('migrations') await migrateDatabase('migrations')
} }
logger.info('API started')
} }

BIN
bun.lockb

Binary file not shown.