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 "./globals.css";
|
||||
import { AuthProvider } from "@/contexts/AuthContext";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import LayoutClient from "./layout-client";
|
||||
import { GoogleOAuthProvider } from "@react-oauth/google";
|
||||
import { Providers } from "./providers";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Thé Tip Top - Jeu Concours",
|
||||
|
|
@ -35,26 +34,14 @@ export const metadata: Metadata = {
|
|||
},
|
||||
};
|
||||
|
||||
const googleClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '';
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const content = (
|
||||
<AuthProvider>
|
||||
<LayoutClient>{children}</LayoutClient>
|
||||
</AuthProvider>
|
||||
);
|
||||
|
||||
return (
|
||||
<html lang="fr">
|
||||
<body className="min-h-screen flex flex-col bg-gray-50">
|
||||
{googleClientId ? (
|
||||
<GoogleOAuthProvider clientId={googleClientId}>
|
||||
{content}
|
||||
</GoogleOAuthProvider>
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
<Toaster
|
||||
<Providers>
|
||||
<LayoutClient>{children}</LayoutClient>
|
||||
</Providers>
|
||||
<Toaster
|
||||
position="top-right"
|
||||
toastOptions={{
|
||||
duration: 4000,
|
||||
|
|
|
|||
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