fix: move GoogleOAuthProvider to client component to fix SSR errors
This commit is contained in:
parent
7995b65ebe
commit
666fb1a1ac
|
|
@ -1,9 +1,8 @@
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import { AuthProvider } from "@/contexts/AuthContext";
|
|
||||||
import { Toaster } from "react-hot-toast";
|
import { Toaster } from "react-hot-toast";
|
||||||
import LayoutClient from "./layout-client";
|
import LayoutClient from "./layout-client";
|
||||||
import { GoogleOAuthProvider } from "@react-oauth/google";
|
import { Providers } from "./providers";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Thé Tip Top - Jeu Concours",
|
title: "Thé Tip Top - Jeu Concours",
|
||||||
|
|
@ -35,25 +34,13 @@ export const metadata: Metadata = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const googleClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '';
|
|
||||||
|
|
||||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||||
const content = (
|
|
||||||
<AuthProvider>
|
|
||||||
<LayoutClient>{children}</LayoutClient>
|
|
||||||
</AuthProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<body className="min-h-screen flex flex-col bg-gray-50">
|
<body className="min-h-screen flex flex-col bg-gray-50">
|
||||||
{googleClientId ? (
|
<Providers>
|
||||||
<GoogleOAuthProvider clientId={googleClientId}>
|
<LayoutClient>{children}</LayoutClient>
|
||||||
{content}
|
</Providers>
|
||||||
</GoogleOAuthProvider>
|
|
||||||
) : (
|
|
||||||
content
|
|
||||||
)}
|
|
||||||
<Toaster
|
<Toaster
|
||||||
position="top-right"
|
position="top-right"
|
||||||
toastOptions={{
|
toastOptions={{
|
||||||
|
|
|
||||||
25
app/providers.tsx
Normal file
25
app/providers.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { GoogleOAuthProvider } from "@react-oauth/google";
|
||||||
|
import { AuthProvider } from "@/contexts/AuthContext";
|
||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
export function Providers({ children }: { children: ReactNode }) {
|
||||||
|
const googleClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '';
|
||||||
|
|
||||||
|
const content = (
|
||||||
|
<AuthProvider>
|
||||||
|
{children}
|
||||||
|
</AuthProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (googleClientId) {
|
||||||
|
return (
|
||||||
|
<GoogleOAuthProvider clientId={googleClientId}>
|
||||||
|
{content}
|
||||||
|
</GoogleOAuthProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user