fix
This commit is contained in:
@@ -14,10 +14,10 @@ async function connectDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(req) {
|
export async function POST(req) {
|
||||||
console.log('Received request:', req); // Log the full request
|
console.log('Received request:', req);
|
||||||
|
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
console.log('Method not allowed'); // Log if method is not POST
|
console.log('Method not allowed');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Method Not Allowed' },
|
{ message: 'Method Not Allowed' },
|
||||||
{ status: 405 }
|
{ status: 405 }
|
||||||
@@ -27,15 +27,16 @@ export async function POST(req) {
|
|||||||
try {
|
try {
|
||||||
const webhookSignature = req.headers.get('clerk-signature');
|
const webhookSignature = req.headers.get('clerk-signature');
|
||||||
const payload = JSON.stringify(await req.json());
|
const payload = JSON.stringify(await req.json());
|
||||||
|
console.log('Webhook Payload:', payload);
|
||||||
console.log('Webhook Payload:', payload); // Log the webhook payload
|
console.log('Received Clerk Signature:', webhookSignature);
|
||||||
|
|
||||||
const hmac = crypto.createHmac('sha256', CLERK_WEBHOOK_SECRET);
|
const hmac = crypto.createHmac('sha256', CLERK_WEBHOOK_SECRET);
|
||||||
hmac.update(payload);
|
hmac.update(payload);
|
||||||
const computedSignature = hmac.digest('hex');
|
const computedSignature = hmac.digest('hex');
|
||||||
|
console.log('Computed Signature:', computedSignature);
|
||||||
|
|
||||||
if (computedSignature !== webhookSignature) {
|
if (computedSignature !== webhookSignature) {
|
||||||
console.log('Invalid webhook signature'); // Log if signature is invalid
|
console.log('Invalid webhook signature');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Invalid webhook signature' },
|
{ message: 'Invalid webhook signature' },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@@ -77,14 +78,14 @@ export async function POST(req) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await user.save();
|
await user.save();
|
||||||
console.log('User created successfully');
|
console.log('User created successfully');
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'User successfully created' },
|
{ message: 'User successfully created' },
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error during webhook processing:', error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Internal server error' },
|
{ message: 'Internal server error' },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
|
|||||||
Reference in New Issue
Block a user