Support sub-path deploy via NEXT_PUBLIC_BASE_PATH (loma.chat/pagiva)
Adds basePath config, withBase/appUrl helpers, base-path-aware cookies, OAuth redirects, manifest, service worker and cron runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { BASE_PATH, appUrl } from "@/lib/base-path";
|
||||
import { NextResponse } from "next/server";
|
||||
import { getCurrentUser, isSuperadmin } from "@/lib/auth/user";
|
||||
import { authorizeUrl, createOAuthState, OAUTH_STATE_COOKIE } from "@/lib/facebook/oauth";
|
||||
@@ -6,8 +7,9 @@ import { safeFacebookErrorMessage } from "@/lib/facebook/client";
|
||||
/** SUPERADMIN only: redirects to the Facebook consent dialog. */
|
||||
export async function GET(req: Request) {
|
||||
const origin = new URL(req.url).origin;
|
||||
const root = appUrl(origin);
|
||||
const user = await getCurrentUser();
|
||||
if (!user || !isSuperadmin(user)) return NextResponse.redirect(new URL("/pages?fb_error=forbidden", origin));
|
||||
if (!user || !isSuperadmin(user)) return NextResponse.redirect(`${root}/pages?fb_error=forbidden`);
|
||||
|
||||
try {
|
||||
const { nonce, cookie } = await createOAuthState(user.id);
|
||||
@@ -17,12 +19,12 @@ export async function GET(req: Request) {
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
// Lax: must survive the top-level redirect back from facebook.com.
|
||||
sameSite: "lax",
|
||||
path: "/api/facebook/oauth",
|
||||
path: `${BASE_PATH}/api/facebook/oauth`,
|
||||
maxAge: 600,
|
||||
});
|
||||
return res;
|
||||
} catch (e) {
|
||||
const msg = safeFacebookErrorMessage(e, "fb:oauth:start");
|
||||
return NextResponse.redirect(new URL(`/pages?fb_error=${encodeURIComponent(msg)}`, origin));
|
||||
return NextResponse.redirect(`${root}/pages?fb_error=${encodeURIComponent(msg)}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user