22 lines
913 B
TypeScript
22 lines
913 B
TypeScript
export const dynamic = 'force-dynamic'
|
|
|
|
import { timingSafeEqual } from 'crypto'
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
import { createClient } from '@/lib/supabase/server'
|
|
import { sendEffectivenessRecheckNotifications } from '@/lib/notifications/effectiveness-recheck'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const auth = request.headers.get('authorization') ?? ''
|
|
const expected = `Bearer ${process.env.CRON_SECRET ?? ''}`
|
|
const authBuf = Buffer.from(auth, 'utf8')
|
|
const expectedBuf = Buffer.from(expected, 'utf8')
|
|
const valid = authBuf.length === expectedBuf.length && timingSafeEqual(authBuf, expectedBuf)
|
|
if (!valid) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const supabase = await createClient()
|
|
const { notified } = await sendEffectivenessRecheckNotifications(supabase)
|
|
return NextResponse.json({ ok: true, notified })
|
|
}
|