Skip to content

Commit

Permalink
chore(docs): add cronjob to drop webauthn KV daily
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed May 12, 2024
1 parent 076a0de commit 2a1e244
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
32 changes: 32 additions & 0 deletions docs/app/api/cron/route.ts
@@ -0,0 +1,32 @@
import { createClient } from "@vercel/kv"
import { NextResponse, NextRequest } from "next/server"

export async function GET(req: NextRequest) {
// Check Authorization
const authHeader = req.headers.get("authorization")
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return new NextResponse("Unauthorized", {
status: 401,
})
}

// Get Vercel KV client
const webAuthnKV = createClient({
url: process.env.KV_REST_API_URL!,
token: process.env.KV_REST_API_TOKEN!,
})

// Drop all WebAuthn authenticators
await webAuthnKV.flushall()

// Verify
const allKeys = await webAuthnKV.keys("*")

if (!allKeys.length) {
return NextResponse.json({ ok: true })
} else {
return new NextResponse("Flush Failed", {
status: 500,
})
}
}
1 change: 1 addition & 0 deletions docs/package.json
Expand Up @@ -31,6 +31,7 @@
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-tabs": "^1.0.4",
"@vercel/analytics": "^1.2.2",
"@vercel/kv": "^1.0.1",
"algoliasearch": "^4.23.3",
"classnames": "^2.5.1",
"next": "14.2.1",
Expand Down
6 changes: 6 additions & 0 deletions docs/vercel.json
Expand Up @@ -11,6 +11,12 @@
]
}
],
"crons": [
{
"path": "/api/cron",
"schedule": "0 1 * * *"
}
],
"redirects": [
{
"source": "/security.txt",
Expand Down
34 changes: 27 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a1e244

Please sign in to comment.