NextJS(13) API call cache MISS

Hey everyone hoping for some help with an issue that is cause me a mountain of headaches. My app is having webhooks forwarded to my API route from StipeCLI. if a certain event type is forwarded I want to fetch an API route in my Next app. shown below:

(BEEN STUCK FOR A WEEK< PLZ HELP)
 switch (event.type) {
    case 'checkout.session.completed':
      const reqUrl = new URL(req.url);

      await fetch(`${reqUrl.origin}/api/clerk/add-credits`, {
        method: 'GET',
      });
      console.log('✅ checkout session completed webhook received');
      break;
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

below is the /api/clerk/add-credits route I want to fetch
import { auth, clerkClient } from '@clerk/nextjs/server';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest, res: NextResponse) {
  res.headers.set('Access-Control-Allow-Origin', '*');
  res.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
  res.headers.set(
    'Access-Control-Allow-Headers',
    'Content-Type, Authorization'
  );
  res.headers.set('Access-Control-Allow-Credentials', 'true');

  const { userId } = auth();
  if (typeof userId !== 'string') return;

  const user = await clerkClient.users.getUser(userId);
  const credits: any = user.publicMetadata.credits;

  try {
    const updatedUser = await clerkClient.users.updateUserMetadata(userId, {
      publicMetadata: {
        credits: credits + 100,
      },
    });
    NextResponse.json({ success: true, user: updatedUser });
    console.log('added credits');
  } catch (err) {
    console.error('error deducting credits', err);
  }
}



My issue is when the fetch runs i get a console message of :
┌ POST /api/stripe/webhook 200 in 1008m

─ GET http://localhost:3000/api/clerk/add-credits 200 in 930ms (cache: MISS)
Screenshot_2023-05-23_at_5.49.10_am.png
Screenshot_2023-05-23_at_5.49.29_am.png
Screenshot_2023-05-23_at_5.49.43_am.png
Was this page helpful?