Files
agent-bounty-protocol/apps/web/src/middleware.ts
OG T bcfd5917a1
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 7s
feat(web): add affiliate kickback program for agents
2026-06-07 22:57:03 +08:00

38 lines
975 B
TypeScript

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const url = request.nextUrl;
// Check if there is a referral parameter ?ref=
const ref = url.searchParams.get('ref');
if (ref) {
const response = NextResponse.redirect(url.pathname);
// Set cookie for 30 days
response.cookies.set('vw_referral_agent', ref, {
maxAge: 30 * 24 * 60 * 60,
path: '/',
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
});
return response;
}
return NextResponse.next();
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
};