fix: make Google and Facebook OAuth optional to prevent errors
- Make GoogleOAuthProvider conditional in layout.tsx (only render if clientId exists) - Add hasGoogleAuth and hasFacebookAuth flags in login page - Conditionally render OAuth buttons and section only when configured - Add fallback message when OAuth is not configured - Prevents "Missing required parameter client_id" error when NEXT_PUBLIC_GOOGLE_CLIENT_ID is not set This allows the app to run without OAuth credentials configured, making deployment easier when OAuth is not yet set up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7347d77ec6
commit
f82985f84e
|
|
@ -38,12 +38,22 @@ export const metadata: Metadata = {
|
||||||
const googleClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '';
|
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">
|
||||||
<GoogleOAuthProvider clientId={googleClientId}>
|
{googleClientId ? (
|
||||||
<AuthProvider>
|
<GoogleOAuthProvider clientId={googleClientId}>
|
||||||
<LayoutClient>{children}</LayoutClient>
|
{content}
|
||||||
|
</GoogleOAuthProvider>
|
||||||
|
) : (
|
||||||
|
content
|
||||||
|
)}
|
||||||
<Toaster
|
<Toaster
|
||||||
position="top-right"
|
position="top-right"
|
||||||
toastOptions={{
|
toastOptions={{
|
||||||
|
|
@ -66,8 +76,6 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</AuthProvider>
|
|
||||||
</GoogleOAuthProvider>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ export default function LoginPage() {
|
||||||
const [isFacebookLoading, setIsFacebookLoading] = useState(false);
|
const [isFacebookLoading, setIsFacebookLoading] = useState(false);
|
||||||
const [isFacebookSDKLoaded, setIsFacebookSDKLoaded] = useState(false);
|
const [isFacebookSDKLoaded, setIsFacebookSDKLoaded] = useState(false);
|
||||||
|
|
||||||
|
const hasGoogleAuth = !!process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID;
|
||||||
|
const hasFacebookAuth = !!process.env.NEXT_PUBLIC_FACEBOOK_APP_ID;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Initialiser le SDK Facebook au chargement de la page
|
// Initialiser le SDK Facebook au chargement de la page
|
||||||
initFacebookSDK()
|
initFacebookSDK()
|
||||||
|
|
@ -51,7 +54,7 @@ export default function LoginPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleGoogleLogin = useGoogleLogin({
|
const handleGoogleLogin = hasGoogleAuth ? useGoogleLogin({
|
||||||
onSuccess: async (tokenResponse) => {
|
onSuccess: async (tokenResponse) => {
|
||||||
setIsGoogleLoading(true);
|
setIsGoogleLoading(true);
|
||||||
console.log('🔑 Token Google reçu:', tokenResponse);
|
console.log('🔑 Token Google reçu:', tokenResponse);
|
||||||
|
|
@ -69,7 +72,9 @@ export default function LoginPage() {
|
||||||
},
|
},
|
||||||
flow: 'implicit',
|
flow: 'implicit',
|
||||||
scope: 'openid email profile',
|
scope: 'openid email profile',
|
||||||
});
|
}) : () => {
|
||||||
|
toast.error("La connexion Google n'est pas configurée");
|
||||||
|
};
|
||||||
|
|
||||||
const handleFacebookLogin = async () => {
|
const handleFacebookLogin = async () => {
|
||||||
if (!isFacebookSDKLoaded) {
|
if (!isFacebookSDKLoaded) {
|
||||||
|
|
@ -142,63 +147,69 @@ export default function LoginPage() {
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="mt-6">
|
{(hasGoogleAuth || hasFacebookAuth) && (
|
||||||
<div className="relative">
|
<div className="mt-6">
|
||||||
<div className="absolute inset-0 flex items-center">
|
<div className="relative">
|
||||||
<div className="w-full border-t border-gray-300" />
|
<div className="absolute inset-0 flex items-center">
|
||||||
|
<div className="w-full border-t border-gray-300" />
|
||||||
|
</div>
|
||||||
|
<div className="relative flex justify-center text-sm">
|
||||||
|
<span className="px-2 bg-white text-gray-500">
|
||||||
|
Ou continuer avec
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="relative flex justify-center text-sm">
|
|
||||||
<span className="px-2 bg-white text-gray-500">
|
<div className={`mt-6 grid ${hasGoogleAuth && hasFacebookAuth ? 'grid-cols-2' : 'grid-cols-1'} gap-3`}>
|
||||||
Ou continuer avec
|
{hasGoogleAuth && (
|
||||||
</span>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => handleGoogleLogin()}
|
||||||
|
disabled={isGoogleLoading}
|
||||||
|
isLoading={isGoogleLoading}
|
||||||
|
fullWidth
|
||||||
|
>
|
||||||
|
<svg className="w-5 h-5 mr-2" viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
fill="#4285F4"
|
||||||
|
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
fill="#34A853"
|
||||||
|
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
fill="#FBBC05"
|
||||||
|
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
fill="#EA4335"
|
||||||
|
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
Google
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{hasFacebookAuth && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleFacebookLogin}
|
||||||
|
disabled={isFacebookLoading || !isFacebookSDKLoaded}
|
||||||
|
isLoading={isFacebookLoading}
|
||||||
|
fullWidth
|
||||||
|
>
|
||||||
|
<svg className="w-5 h-5 mr-2" fill="#1877F2" viewBox="0 0 24 24">
|
||||||
|
<path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
|
||||||
|
</svg>
|
||||||
|
Facebook
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
<div className="mt-6 grid grid-cols-2 gap-3">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => handleGoogleLogin()}
|
|
||||||
disabled={isGoogleLoading}
|
|
||||||
isLoading={isGoogleLoading}
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
<svg className="w-5 h-5 mr-2" viewBox="0 0 24 24">
|
|
||||||
<path
|
|
||||||
fill="#4285F4"
|
|
||||||
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
fill="#34A853"
|
|
||||||
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
fill="#FBBC05"
|
|
||||||
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
fill="#EA4335"
|
|
||||||
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
Google
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
onClick={handleFacebookLogin}
|
|
||||||
disabled={isFacebookLoading || !isFacebookSDKLoaded}
|
|
||||||
isLoading={isFacebookLoading}
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
<svg className="w-5 h-5 mr-2" fill="#1877F2" viewBox="0 0 24 24">
|
|
||||||
<path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
|
|
||||||
</svg>
|
|
||||||
Facebook
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p className="mt-8 text-center text-sm text-gray-600">
|
<p className="mt-8 text-center text-sm text-gray-600">
|
||||||
Vous n'avez pas de compte ?{" "}
|
Vous n'avez pas de compte ?{" "}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user