Files
hats-app/proxy.ts
T
Ichsan Kurniawan c1b41f0718 Update loader image to webp and update app metadata
Replaced the loader animation from GIF to WEBP for improved performance. Updated the HATs Team page description and corrected the release note date. Enhanced package.json with project metadata and incremented version to 1.1.0. Adjusted proxy matcher to exclude hats-team and release-notes routes.
2026-01-28 19:27:03 +07:00

53 lines
1.8 KiB
TypeScript

import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api/ routes
* 2. /_next/ (Next.js internals)
* 3. /_proxy/ (special page for OG tags proxying)
* 4. /_static (inside /public)
* 5. /_vercel (Vercel internals)
* 6. /favicon.ico, /sitemap.xml (static files)
* 7. /auth page
*/
"/((?!api/|_next/|_proxy/|_static|_vercel|auth|terms|privacy-policy|hats-team|release-notes|not-found|avatars/|assets/|files/|admin/sourceMap/chrome/css/|admin/administration/sourceMap/chrome/css/|firebase-messaging-sw.js|favicon.ico|sitemap.xml).*)",
],
// matcher: [
// "/",
// "/admin/:path*",
// // '/auth' ==> cause redirect panjang
// ]
};
export default withAuth(
// `withAuth` augments your `Request` with the user's token.
async function proxy(req) {
const session: any = req.nextauth.token
const path = req.nextUrl.pathname
// console.log("URL", path)
if (path === 'admin' || path.startsWith('/admin')) {
if (!session.detail.role.allow_admin_panel) {
// return NextResponse.redirect(new URL(basePath + '/', req.url))
return NextResponse.redirect(new URL('/', req.url))
}
}
if (path === '/users/sign_in') {
return NextResponse.redirect(new URL('/', req.url))
}
if (session?.error === 'RefreshAccessTokenError') {
// return NextResponse.redirect(new URL(`/auth?callbackUrl=${req.url}&error=Your session has expired !`, req.url))
return NextResponse.redirect(new URL(`/auth?&error=Your session has expired !`, req.url))
}
},
// {
// pages: {
// signIn: `/auth` //<-- i mean this, avoid basePath for defaultValue
// },
// }
);