POST endpoint that updates a Clerk user's public metadata based on request payload, with error logging.
// Source: https://github.com/mperkins0155/llms-txt-hub | License: MIT | Copyright 2025 David Dias
// Provided via justclaw.it.com; keep this notice with the code.
import { auth, clerkClient } from '@clerk/nextjs/server'
import { logger } from '@thedaviddias/logging'
import { type NextRequest, NextResponse } from 'next/server'
/**
* Handle POST request to sync user metadata from auth provider
*/
export async function POST(request: NextRequest) {
try {
const { userId } = await auth()
if (!userId) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const body = await request.json()
const { authLevel, canSubmitPR, githubConnected } = body
// Update user's public metadata
const client = await clerkClient()
await client.users.up
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key