2026-01-19 12:55:41 +07:00
|
|
|
import { NextResponse, NextRequest } from 'next/server';
|
|
|
|
|
import { cookies } from 'next/headers'
|
|
|
|
|
import createIntlMiddleware from 'next-intl/middleware'
|
|
|
|
|
import { routing } from '@/i18n/routing'
|
2026-04-06 16:08:36 +07:00
|
|
|
import { decrypt } from '@/app/actions/session';
|
2026-01-19 12:55:41 +07:00
|
|
|
|
|
|
|
|
const intlMiddleware = createIntlMiddleware(routing);
|
|
|
|
|
|
|
|
|
|
export default async function proxy(request: NextRequest) {
|
|
|
|
|
const path = request.nextUrl.pathname;
|
|
|
|
|
|
2026-04-06 16:08:36 +07:00
|
|
|
const cookie = (await cookies()).get('session')?.value;
|
|
|
|
|
const session = await decrypt(cookie);
|
|
|
|
|
console.log(session);
|
|
|
|
|
|
2026-01-19 12:55:41 +07:00
|
|
|
if (
|
|
|
|
|
path.startsWith('/_next') ||
|
|
|
|
|
path.includes('.')
|
|
|
|
|
) {
|
|
|
|
|
return NextResponse.next()
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 16:08:36 +07:00
|
|
|
const requestHeaders = new Headers(request.headers);
|
|
|
|
|
requestHeaders.set('x-pathname', path);
|
|
|
|
|
|
2026-01-19 12:55:41 +07:00
|
|
|
const intlResponse = intlMiddleware(request);
|
|
|
|
|
|
|
|
|
|
if (intlResponse) {
|
2026-04-06 16:08:36 +07:00
|
|
|
const response = new NextResponse(intlResponse.body, intlResponse);
|
|
|
|
|
response.headers.set('x-pathname', path);
|
|
|
|
|
|
|
|
|
|
/* if (!session?.token) {
|
|
|
|
|
const loginUrl = new URL('/login', request.nextUrl)
|
|
|
|
|
loginUrl.searchParams.set('locale', request.nextUrl.locale || 'ru')
|
|
|
|
|
return NextResponse.redirect(loginUrl)
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
return intlResponse;
|
2026-01-19 12:55:41 +07:00
|
|
|
}
|
|
|
|
|
|
2026-04-06 16:08:36 +07:00
|
|
|
return NextResponse.next({
|
|
|
|
|
request: {
|
|
|
|
|
headers: requestHeaders,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-01-19 12:55:41 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const config = {
|
2026-01-22 17:30:46 +07:00
|
|
|
matcher: ['/((?!_next/static|_next/image|.*\\.png$).*)']
|
2026-01-19 12:55:41 +07:00
|
|
|
};
|