Reduce Vercel CPU usage by narrowing auth checks
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Analytics } from "@vercel/analytics/react";
|
import { Analytics } from "@vercel/analytics/react";
|
||||||
import { SpeedInsights } from "@vercel/speed-insights/next";
|
import { SpeedInsights } from "@vercel/speed-insights/next";
|
||||||
import { WebVitalsReporter } from "@/components/observability/WebVitalsReporter";
|
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@@ -35,7 +34,6 @@ export default function RootLayout({
|
|||||||
</head>
|
</head>
|
||||||
<body className="min-h-screen font-sans antialiased">
|
<body className="min-h-screen font-sans antialiased">
|
||||||
{children}
|
{children}
|
||||||
<WebVitalsReporter />
|
|
||||||
<Analytics />
|
<Analytics />
|
||||||
<SpeedInsights />
|
<SpeedInsights />
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -57,6 +57,16 @@ function isPublicApi(pathname: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldRefreshOptionalSupabaseSession(pathname: string) {
|
||||||
|
return (
|
||||||
|
pathname.startsWith("/account") ||
|
||||||
|
pathname.startsWith("/ops") ||
|
||||||
|
pathname.startsWith("/api/ops/") ||
|
||||||
|
pathname.startsWith("/api/payments/") ||
|
||||||
|
pathname === "/api/system/status"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function handleLegacyTokenGate(request: NextRequest) {
|
function handleLegacyTokenGate(request: NextRequest) {
|
||||||
const requiredToken = process.env.POLYWEATHER_DASHBOARD_ACCESS_TOKEN?.trim();
|
const requiredToken = process.env.POLYWEATHER_DASHBOARD_ACCESS_TOKEN?.trim();
|
||||||
if (!requiredToken) {
|
if (!requiredToken) {
|
||||||
@@ -144,6 +154,15 @@ async function handleSupabaseAuthGate(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleSupabaseOptionalSession(request: NextRequest) {
|
async function handleSupabaseOptionalSession(request: NextRequest) {
|
||||||
|
const { pathname } = request.nextUrl;
|
||||||
|
if (
|
||||||
|
isPublicPage(pathname) ||
|
||||||
|
isPublicApi(pathname) ||
|
||||||
|
!shouldRefreshOptionalSupabaseSession(pathname)
|
||||||
|
) {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
const response = NextResponse.next({
|
const response = NextResponse.next({
|
||||||
request: {
|
request: {
|
||||||
headers: request.headers,
|
headers: request.headers,
|
||||||
|
|||||||
Reference in New Issue
Block a user