fix redirect
This commit is contained in:
parent
f2d3e68f5d
commit
2976475ddd
@ -1,33 +1,3 @@
|
|||||||
//import { NextRequest, NextResponse } from "next/server";
|
|
||||||
|
|
||||||
//import { ROUTES } from "@/shared/constants/client-routes";
|
|
||||||
|
|
||||||
//export async function GET(req: NextRequest) {
|
|
||||||
// const { searchParams } = req.nextUrl;
|
|
||||||
// const token = searchParams.get("jwtToken");
|
|
||||||
// const productId = searchParams.get("productId");
|
|
||||||
// const placementId = searchParams.get("placementId");
|
|
||||||
// const paywallId = searchParams.get("paywallId");
|
|
||||||
|
|
||||||
// const redirectUrl = new URL(`${ROUTES.payment()}`, process.env.NEXT_PUBLIC_APP_URL || "");
|
|
||||||
// if (productId) redirectUrl.searchParams.set("productId", productId);
|
|
||||||
// if (placementId) redirectUrl.searchParams.set("placementId", placementId);
|
|
||||||
// if (paywallId) redirectUrl.searchParams.set("paywallId", paywallId);
|
|
||||||
|
|
||||||
// const res = NextResponse.redirect(redirectUrl);
|
|
||||||
|
|
||||||
// res.cookies.set({
|
|
||||||
// name: "accessToken",
|
|
||||||
// value: token || "",
|
|
||||||
// httpOnly: true,
|
|
||||||
// secure: true,
|
|
||||||
// sameSite: "lax",
|
|
||||||
// path: "/",
|
|
||||||
// maxAge: 60 * 60 * 24 * 365,
|
|
||||||
// });
|
|
||||||
// return res;
|
|
||||||
//}
|
|
||||||
|
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
import { ROUTES } from "@/shared/constants/client-routes";
|
import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { type ReactNode,useEffect } from "react";
|
import { type ReactNode,useEffect } from "react";
|
||||||
|
|
||||||
|
import { fetchMe } from "@/entities/user/actions";
|
||||||
import { analyticsService } from "@/services/analytics";
|
import { analyticsService } from "@/services/analytics";
|
||||||
|
|
||||||
interface AnalyticsProviderProps {
|
interface AnalyticsProviderProps {
|
||||||
@ -16,8 +17,21 @@ interface AnalyticsProviderProps {
|
|||||||
*/
|
*/
|
||||||
export function AnalyticsProvider({ children }: AnalyticsProviderProps) {
|
export function AnalyticsProvider({ children }: AnalyticsProviderProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Initialize analytics service
|
// Initialize analytics service with server-side data
|
||||||
analyticsService.initialize();
|
const initAnalytics = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetchMe();
|
||||||
|
if (response.data && !response.error) {
|
||||||
|
await analyticsService.initialize(response.data.user);
|
||||||
|
} else {
|
||||||
|
await analyticsService.initialize(null);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
await analyticsService.initialize(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
initAnalytics();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
import type { IMeResponse, IUser } from "@/entities/user/types";
|
import type { IUser } from "@/entities/user/types";
|
||||||
import { http } from "@/shared/api/httpClient";
|
|
||||||
import { API_ROUTES } from "@/shared/constants/api-routes";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analytics Service
|
* Analytics Service
|
||||||
@ -23,14 +21,13 @@ export class AnalyticsService {
|
|||||||
/**
|
/**
|
||||||
* Initialize analytics service with user data
|
* Initialize analytics service with user data
|
||||||
*/
|
*/
|
||||||
async initialize(): Promise<void> {
|
async initialize(userData: IUser | null): Promise<void> {
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await http.get<IMeResponse>(API_ROUTES.usersMe());
|
this.user = userData;
|
||||||
this.user = response.user;
|
|
||||||
|
|
||||||
// Set user parameters in analytics
|
// Set user parameters in analytics
|
||||||
await this.setUserParameters();
|
await this.setUserParameters();
|
||||||
|
|||||||
@ -58,6 +58,22 @@ class HttpClient {
|
|||||||
const fullUrl = this.buildUrl(rootUrl, path, query);
|
const fullUrl = this.buildUrl(rootUrl, path, query);
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
const headers = new Headers();
|
||||||
|
let accessToken: string | undefined;
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
const { getServerAccessToken } = await import("../auth/token");
|
||||||
|
accessToken = await getServerAccessToken();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const { getClientAccessToken } = await import("../auth/token");
|
||||||
|
accessToken = getClientAccessToken();
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (accessToken) headers.set("Authorization", `Bearer ${accessToken}`);
|
||||||
|
headers.set("Content-Type", "application/json");
|
||||||
|
|
||||||
// Log API request (both client and server with ENV control)
|
// Log API request (both client and server with ENV control)
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
// Client-side logging
|
// Client-side logging
|
||||||
@ -78,22 +94,6 @@ class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = new Headers();
|
|
||||||
let accessToken: string | undefined;
|
|
||||||
if (typeof window === "undefined") {
|
|
||||||
const { getServerAccessToken } = await import("../auth/token");
|
|
||||||
accessToken = await getServerAccessToken();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
const { getClientAccessToken } = await import("../auth/token");
|
|
||||||
accessToken = getClientAccessToken();
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (accessToken) headers.set("Authorization", `Bearer ${accessToken}`);
|
|
||||||
headers.set("Content-Type", "application/json");
|
|
||||||
|
|
||||||
const res = await fetch(fullUrl, {
|
const res = await fetch(fullUrl, {
|
||||||
method,
|
method,
|
||||||
body: body ? JSON.stringify(body) : undefined,
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user