middleware
Unanswered
Mini Lop posted this in #help-forum
Mini LopOP
please i want to add my custom function to middleware with clerk , but clerk is not working when i called auth() ,currentUser(). please help me
import { clerkMiddleware } from "@clerk/nextjs/server";
import { NextRequest, NextResponse } from "next/server";
export default clerkMiddleware ({
publicRoutes: ['/', '/api/webhooks/clerk', '/api/webhooks/stripe']
});
// managing the referral system
export function middleware(request: NextRequest) {
const response = NextResponse.next();
const referral = request.nextUrl.searchParams.get('ref');
if (request.nextUrl.pathname.startsWith('/sign-up')) {
// setting referral code from searchparams to cookies
response.cookies.set({
name: "referral_code",
value:
})
}
return response;
}
export const config = {
matcher: ["/((?!.+\.[\w]+$|_next).)", "/", "/(api|trpc)(.)","/profile"],
};
import { clerkMiddleware } from "@clerk/nextjs/server";
import { NextRequest, NextResponse } from "next/server";
export default clerkMiddleware ({
publicRoutes: ['/', '/api/webhooks/clerk', '/api/webhooks/stripe']
});
// managing the referral system
export function middleware(request: NextRequest) {
const response = NextResponse.next();
const referral = request.nextUrl.searchParams.get('ref');
if (request.nextUrl.pathname.startsWith('/sign-up')) {
// setting referral code from searchparams to cookies
response.cookies.set({
name: "referral_code",
value:
${referral}})
}
return response;
}
export const config = {
matcher: ["/((?!.+\.[\w]+$|_next).)", "/", "/(api|trpc)(.)","/profile"],
};