Gate analytics and cache public API requests
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"use client";
|
||||
|
||||
const ANALYTICS_ENABLED =
|
||||
process.env.NEXT_PUBLIC_POLYWEATHER_APP_ANALYTICS === "true";
|
||||
|
||||
type TrackableAnalyticsEvent =
|
||||
| "signup_completed"
|
||||
| "dashboard_active"
|
||||
@@ -68,7 +71,7 @@ export function trackAppEvent(
|
||||
eventType: TrackableAnalyticsEvent,
|
||||
payload: Record<string, unknown> = {},
|
||||
) {
|
||||
if (!isClient()) return;
|
||||
if (!isClient() || !ANALYTICS_ENABLED) return;
|
||||
const body = {
|
||||
event_type: eventType,
|
||||
client_id: getAnalyticsClientId() || undefined,
|
||||
|
||||
@@ -11,6 +11,10 @@ type HeaderBuildResult = {
|
||||
response: NextResponse | null;
|
||||
};
|
||||
|
||||
type HeaderBuildOptions = {
|
||||
includeSupabaseIdentity?: boolean;
|
||||
};
|
||||
|
||||
function extractBearerToken(headerValue: string | null) {
|
||||
if (!headerValue) return "";
|
||||
const parts = headerValue.trim().split(/\s+/);
|
||||
@@ -22,6 +26,7 @@ function extractBearerToken(headerValue: string | null) {
|
||||
|
||||
export async function buildBackendRequestHeaders(
|
||||
request: NextRequest,
|
||||
options?: HeaderBuildOptions,
|
||||
): Promise<HeaderBuildResult> {
|
||||
const headers = new Headers({
|
||||
Accept: "application/json",
|
||||
@@ -32,7 +37,8 @@ export async function buildBackendRequestHeaders(
|
||||
}
|
||||
|
||||
const incomingAuth = extractBearerToken(request.headers.get("authorization"));
|
||||
if (hasSupabaseServerEnv()) {
|
||||
const includeSupabaseIdentity = options?.includeSupabaseIdentity !== false;
|
||||
if (hasSupabaseServerEnv() && includeSupabaseIdentity) {
|
||||
const passthroughResponse = new NextResponse(null, { status: 200 });
|
||||
const supabase = createSupabaseRouteClient(request, passthroughResponse);
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user