import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server' import { NextResponse } from 'next/server' const isPublicRoute = createRouteMatcher([ '/sign-in(.*)', '/sign-up(.*)', '/api/github/webhook' ]) export default clerkMiddleware(async (auth, req) => { // Skip auth check for webhook endpoint if (req.nextUrl.pathname === '/api/github/webhook') { return NextResponse.next() } // const session = await auth() // console.log(session.sessionClaims) // If not public route, protect it if (!isPublicRoute(req)) { await auth.protect() } // Get session data // If on public route and authenticated, redirect to home // if (isPublicRoute(req) && userId) { // return NextResponse.redirect(new URL('/home', req.url)) // } // Get GitHub token if user is authenticated // const claims = sessionClaims as { oauth_access_tokens?: { github?: string } } // if (userId && claims?.oauth_access_tokens?.github) { // const headers = new Headers() // headers.set('x-github-token', claims.oauth_access_tokens.github) // return NextResponse.next({ // request: { // headers // } // }) // } // return NextResponse.next() }) export const config = { matcher: [ // Skip Next.js internals and all static files, unless found in search params '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', // Always run for API routes '/(api|trpc)(.*)' ] }