UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

45 lines (37 loc) 1.23 kB
import { NextResponse } from 'next/server'; import { authEnv } from '@/config/auth'; import { pino } from '@/libs/logger'; import { NextAuthUserService } from '@/server/services/nextAuthUser'; import { validateRequest } from './validateRequest'; export const POST = async (req: Request): Promise<NextResponse> => { const payload = await validateRequest(req, authEnv.CASDOOR_WEBHOOK_SECRET); if (!payload) { return NextResponse.json( { error: 'webhook verification failed or payload was malformed' }, { status: 400 }, ); } const { action, object } = payload; const nextAuthUserService = new NextAuthUserService(); switch (action) { case 'update-user': { return nextAuthUserService.safeUpdateUser( { provider: 'casdoor', providerAccountId: object.id, }, { avatar: object?.avatar, email: object?.email, fullName: object.displayName, }, ); } default: { pino.warn( `${req.url} received event type "${action}", but no handler is defined for this type`, ); return NextResponse.json({ error: `unrecognised payload type: ${action}` }, { status: 400 }); } } };