chore(app): update Google Analytics ID in layout component
This commit is contained in:
+3
-1
@@ -23,4 +23,6 @@ NEXTAUTH_SECRET="your-super-secret-key-change-in-production"
|
|||||||
# GITHUB_CLIENT_SECRET=your_client_secret
|
# GITHUB_CLIENT_SECRET=your_client_secret
|
||||||
|
|
||||||
# AI Search (optional - enable aiSearch in prompts.config.ts)
|
# AI Search (optional - enable aiSearch in prompts.config.ts)
|
||||||
# OPENAI_API_KEY=your_openai_api_key
|
# OPENAI_API_KEY=your_openai_api_key
|
||||||
|
|
||||||
|
GOOGLE_ANALYTICS_ID="G-XXXXXXXXX"
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
|
import Script from "next/script";
|
||||||
import { Inter, Noto_Sans_Arabic } from "next/font/google";
|
import { Inter, Noto_Sans_Arabic } from "next/font/google";
|
||||||
import { getMessages, getLocale } from "next-intl/server";
|
import { getMessages, getLocale } from "next-intl/server";
|
||||||
import { Providers } from "@/components/providers";
|
import { Providers } from "@/components/providers";
|
||||||
@@ -92,6 +93,24 @@ export default async function RootLayout({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang={locale} dir={isRtl ? "rtl" : "ltr"} suppressHydrationWarning className={themeClasses} style={themeStyles}>
|
<html lang={locale} dir={isRtl ? "rtl" : "ltr"} suppressHydrationWarning className={themeClasses} style={themeStyles}>
|
||||||
|
<head>
|
||||||
|
{process.env.GOOGLE_ANALYTICS_ID && (
|
||||||
|
<>
|
||||||
|
<Script
|
||||||
|
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GOOGLE_ANALYTICS_ID}`}
|
||||||
|
strategy="afterInteractive"
|
||||||
|
/>
|
||||||
|
<Script id="google-analytics" strategy="afterInteractive">
|
||||||
|
{`
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', '${process.env.GOOGLE_ANALYTICS_ID}');
|
||||||
|
`}
|
||||||
|
</Script>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</head>
|
||||||
<body className={`${fontClasses} antialiased`}>
|
<body className={`${fontClasses} antialiased`}>
|
||||||
<Providers locale={locale} messages={messages} theme={config.theme} branding={config.branding}>
|
<Providers locale={locale} messages={messages} theme={config.theme} branding={config.branding}>
|
||||||
<div className="relative min-h-screen flex flex-col">
|
<div className="relative min-h-screen flex flex-col">
|
||||||
|
|||||||
+17
-10
@@ -124,19 +124,26 @@ async function buildAuthConfig() {
|
|||||||
},
|
},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
async jwt({ token, user, trigger }: { token: any; user?: any; trigger?: string }) {
|
async jwt({ token, user, trigger }: { token: any; user?: any; trigger?: string }) {
|
||||||
// On sign in, add user data to token
|
// On sign in, look up the actual database user by email to ensure correct ID
|
||||||
if (user) {
|
if (user && user.email) {
|
||||||
token.id = user.id;
|
const dbUser = await db.user.findUnique({
|
||||||
token.role = (user as User).role;
|
where: { email: user.email },
|
||||||
token.username = (user as User).username;
|
select: { id: true, role: true, username: true, locale: true },
|
||||||
token.locale = (user as User).locale;
|
});
|
||||||
|
|
||||||
|
if (dbUser) {
|
||||||
|
token.id = dbUser.id;
|
||||||
|
token.role = dbUser.role;
|
||||||
|
token.username = dbUser.username;
|
||||||
|
token.locale = dbUser.locale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always verify user exists in database
|
// On subsequent requests, verify user exists and refresh data
|
||||||
if (token.id) {
|
if (token.id && !user) {
|
||||||
const dbUser = await db.user.findUnique({
|
const dbUser = await db.user.findUnique({
|
||||||
where: { id: token.id as string },
|
where: { id: token.id as string },
|
||||||
select: { role: true, username: true, locale: true },
|
select: { id: true, role: true, username: true, locale: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
// User no longer exists - invalidate token
|
// User no longer exists - invalidate token
|
||||||
@@ -144,7 +151,7 @@ async function buildAuthConfig() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update token with latest user data
|
// Update token with latest user data on explicit update or if data missing
|
||||||
if (trigger === "update" || !token.username) {
|
if (trigger === "update" || !token.username) {
|
||||||
token.role = dbUser.role;
|
token.role = dbUser.role;
|
||||||
token.username = dbUser.username;
|
token.username = dbUser.username;
|
||||||
|
|||||||
Reference in New Issue
Block a user