add console logging
This commit is contained in:
@@ -14,7 +14,10 @@ async function connectDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(req) {
|
export async function POST(req) {
|
||||||
|
console.log('Received request:', req); // Log the full request
|
||||||
|
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
|
console.log('Method not allowed'); // Log if method is not POST
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Method Not Allowed' },
|
{ message: 'Method Not Allowed' },
|
||||||
{ status: 405 }
|
{ status: 405 }
|
||||||
@@ -25,11 +28,14 @@ export async function POST(req) {
|
|||||||
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); // Log the webhook payload
|
||||||
|
|
||||||
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');
|
||||||
|
|
||||||
if (computedSignature !== webhookSignature) {
|
if (computedSignature !== webhookSignature) {
|
||||||
|
console.log('Invalid webhook signature'); // Log if signature is invalid
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Invalid webhook signature' },
|
{ message: 'Invalid webhook signature' },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@@ -41,9 +47,12 @@ export async function POST(req) {
|
|||||||
const { first_name, last_name, email_addresses } = await req.json();
|
const { first_name, last_name, email_addresses } = await req.json();
|
||||||
const email = email_addresses && email_addresses[0] ? email_addresses[0].email_address : null;
|
const email = email_addresses && email_addresses[0] ? email_addresses[0].email_address : null;
|
||||||
|
|
||||||
|
console.log('Clerk Data:', { first_name, last_name, email });
|
||||||
|
|
||||||
const name = first_name && last_name ? `${first_name} ${last_name}` : first_name || last_name;
|
const name = first_name && last_name ? `${first_name} ${last_name}` : first_name || last_name;
|
||||||
|
|
||||||
if (!name || !email) {
|
if (!name || !email) {
|
||||||
|
console.log('Missing name or email');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'Name and email are required' },
|
{ message: 'Name and email are required' },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@@ -52,6 +61,7 @@ export async function POST(req) {
|
|||||||
|
|
||||||
let user = await User.findOne({ email });
|
let user = await User.findOne({ email });
|
||||||
if (user) {
|
if (user) {
|
||||||
|
console.log('User already exists');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'User already exists' },
|
{ message: 'User already exists' },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
@@ -67,13 +77,14 @@ export async function POST(req) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await user.save();
|
await user.save();
|
||||||
|
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);
|
console.error('Error:', 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