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
|
||||
|
||||
# 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 Script from "next/script";
|
||||
import { Inter, Noto_Sans_Arabic } from "next/font/google";
|
||||
import { getMessages, getLocale } from "next-intl/server";
|
||||
import { Providers } from "@/components/providers";
|
||||
@@ -92,6 +93,24 @@ export default async function RootLayout({
|
||||
|
||||
return (
|
||||
<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`}>
|
||||
<Providers locale={locale} messages={messages} theme={config.theme} branding={config.branding}>
|
||||
<div className="relative min-h-screen flex flex-col">
|
||||
|
||||
+17
-10
@@ -124,19 +124,26 @@ async function buildAuthConfig() {
|
||||
},
|
||||
callbacks: {
|
||||
async jwt({ token, user, trigger }: { token: any; user?: any; trigger?: string }) {
|
||||
// On sign in, add user data to token
|
||||
if (user) {
|
||||
token.id = user.id;
|
||||
token.role = (user as User).role;
|
||||
token.username = (user as User).username;
|
||||
token.locale = (user as User).locale;
|
||||
// On sign in, look up the actual database user by email to ensure correct ID
|
||||
if (user && user.email) {
|
||||
const dbUser = await db.user.findUnique({
|
||||
where: { email: user.email },
|
||||
select: { id: true, role: true, username: true, locale: true },
|
||||
});
|
||||
|
||||
if (dbUser) {
|
||||
token.id = dbUser.id;
|
||||
token.role = dbUser.role;
|
||||
token.username = dbUser.username;
|
||||
token.locale = dbUser.locale;
|
||||
}
|
||||
}
|
||||
|
||||
// Always verify user exists in database
|
||||
if (token.id) {
|
||||
// On subsequent requests, verify user exists and refresh data
|
||||
if (token.id && !user) {
|
||||
const dbUser = await db.user.findUnique({
|
||||
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
|
||||
@@ -144,7 +151,7 @@ async function buildAuthConfig() {
|
||||
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) {
|
||||
token.role = dbUser.role;
|
||||
token.username = dbUser.username;
|
||||
|
||||
Reference in New Issue
Block a user