{hasGoogleAuth && (
-
+
)}
{hasFacebookAuth && (
diff --git a/app/profil/page.tsx b/app/profil/page.tsx
index 4d5108d..5d1e433 100644
--- a/app/profil/page.tsx
+++ b/app/profil/page.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useState } from "react";
+import { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useAuth } from "@/contexts/AuthContext";
@@ -21,6 +21,7 @@ export default function ProfilePage() {
const router = useRouter();
const [isEditing, setIsEditing] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
+ const [isReady, setIsReady] = useState(false);
const {
register,
@@ -36,8 +37,15 @@ export default function ProfilePage() {
},
});
- if (!isAuthenticated || !user) {
- router.push(ROUTES.LOGIN);
+ useEffect(() => {
+ if (!isAuthenticated || !user) {
+ router.push(ROUTES.LOGIN);
+ } else {
+ setIsReady(true);
+ }
+ }, [isAuthenticated, user, router]);
+
+ if (!isReady || !user) {
return null;
}
diff --git a/components/GoogleLoginButton.tsx b/components/GoogleLoginButton.tsx
new file mode 100644
index 0000000..7402448
--- /dev/null
+++ b/components/GoogleLoginButton.tsx
@@ -0,0 +1,67 @@
+"use client";
+
+import { useGoogleLogin } from "@react-oauth/google";
+import Button from "@/components/Button";
+import { useAuth } from "@/contexts/AuthContext";
+import { useState } from "react";
+
+interface GoogleLoginButtonProps {
+ disabled?: boolean;
+ fullWidth?: boolean;
+}
+
+export function GoogleLoginButton({ disabled, fullWidth }: GoogleLoginButtonProps) {
+ const { googleLogin } = useAuth();
+ const [isLoading, setIsLoading] = useState(false);
+
+ const googleLoginHandler = useGoogleLogin({
+ onSuccess: async (tokenResponse) => {
+ setIsLoading(true);
+ console.log('🔑 Token Google reçu:', tokenResponse);
+ try {
+ await googleLogin(tokenResponse.access_token);
+ } catch (error) {
+ console.error("Google login error:", error);
+ } finally {
+ setIsLoading(false);
+ }
+ },
+ onError: (error) => {
+ console.error("Google login failed:", error);
+ setIsLoading(false);
+ },
+ flow: 'implicit',
+ scope: 'openid email profile',
+ });
+
+ return (
+
+ );
+}