From ba8bd08c533d1add74fd110027cec03f5d9487d9 Mon Sep 17 00:00:00 2001 From: Patricio Almada Date: Fri, 8 Nov 2024 04:11:47 -0300 Subject: [PATCH] Revert "fix: on click sign in button - you redirect to home page" --- .env.example | 2 -- src/app/auth/page.tsx | 21 ++++++--------------- src/components/AsignarSolicitudButton.tsx | 8 +++----- src/components/auth/Login.tsx | 8 ++------ src/components/auth/SignUp.tsx | 7 ++----- src/components/auth/SocialButton.tsx | 9 ++------- 6 files changed, 15 insertions(+), 40 deletions(-) diff --git a/.env.example b/.env.example index 1ad7baa7..2c15a743 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,3 @@ -NEXT_PUBLIC_BASE_URL=https://ajudadana.es -NEXT_PUBLIC_NODE_ENV=production NEXT_PUBLIC_SUPABASE_URL= NEXT_PUBLIC_SUPABASE_ANON_KEY= SUPABASE_GOOGLE_AUTH_ID= diff --git a/src/app/auth/page.tsx b/src/app/auth/page.tsx index 887b4689..5397547f 100644 --- a/src/app/auth/page.tsx +++ b/src/app/auth/page.tsx @@ -1,26 +1,17 @@ 'use client'; -import { Suspense, useEffect } from 'react'; +import { useEffect } from 'react'; import Login from '../../components/auth/Login'; -import { useRouter, useSearchParams } from 'next/navigation'; +import { useRouter } from 'next/navigation'; import { authService } from '@/lib/service'; -export default function AUthPage() { - return ( - - - - ); -} - -function Auth() { +export default function AuthPage() { const router = useRouter(); - const searchParams = useSearchParams(); - const redirect = searchParams.get('redirect') || '/'; + useEffect(() => { async function fetchSession() { const { data: session } = await authService.getSessionUser(); if (session.user) { - router.push(redirect); + router.push('/'); } } fetchSession(); @@ -28,7 +19,7 @@ function Auth() { return (
- router.push(redirect)} redirectUrl={redirect} /> + (window.location.href = '/')} />
); } diff --git a/src/components/AsignarSolicitudButton.tsx b/src/components/AsignarSolicitudButton.tsx index 92d9474e..fabc1921 100644 --- a/src/components/AsignarSolicitudButton.tsx +++ b/src/components/AsignarSolicitudButton.tsx @@ -10,7 +10,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { toast } from 'sonner'; import Modal from '@/components/Modal'; import { useModal } from '@/context/ModalProvider'; -import { useRouter } from 'next/navigation'; type AsignarSolicitudButtonProps = { helpRequest: HelpRequestData; @@ -21,7 +20,6 @@ export default function AsignarSolicitudButton({ helpRequest }: AsignarSolicitud const session = useSession(); const userId = session.user?.id; const MODAL_NAME = `Solicitud-${helpRequest.id}`; - const router = useRouter(); const { data: assignments, @@ -91,12 +89,12 @@ export default function AsignarSolicitudButton({ helpRequest }: AsignarSolicitud if (!session || !session.user) return ( - + ); // Verifica el email dentro de additional_info utilizando un casting y encadenamiento opcional diff --git a/src/components/auth/Login.tsx b/src/components/auth/Login.tsx index e8014e29..e1a68e01 100644 --- a/src/components/auth/Login.tsx +++ b/src/components/auth/Login.tsx @@ -7,7 +7,6 @@ import SocialButton from './SocialButton'; type LoginProps = { onSuccessCallback: () => void; - redirectUrl?: string; }; type Status = { @@ -22,7 +21,7 @@ type FormData = { privacyPolicy: string; }; -export default function Login({ onSuccessCallback, redirectUrl }: LoginProps) { +export default function Login({ onSuccessCallback }: LoginProps) { const [isSignUp, setIsSignUp] = useState(false); const [formData, setFormData] = useState({ email: '', @@ -199,9 +198,7 @@ export default function Login({ onSuccessCallback, redirectUrl }: LoginProps) {

O prueba con estas opciones:

- - Inicia sesión con Google - + Inicia sesión con Google
)} @@ -210,7 +207,6 @@ export default function Login({ onSuccessCallback, redirectUrl }: LoginProps) { onBackButtonClicked={() => { setIsSignUp(false); }} - callback={onSuccessCallback} /> )} diff --git a/src/components/auth/SignUp.tsx b/src/components/auth/SignUp.tsx index 2cea1e9d..c28d2998 100644 --- a/src/components/auth/SignUp.tsx +++ b/src/components/auth/SignUp.tsx @@ -24,10 +24,9 @@ type Status = { type SignUpProps = { onBackButtonClicked: () => void; - callback?: () => void; }; -export default function SignUp({ onBackButtonClicked, callback = () => {} }: SignUpProps) { +export default function SignUp({ onBackButtonClicked }: SignUpProps) { const [formData, setFormData] = useState({ nombre: '', email: '', @@ -123,9 +122,7 @@ export default function SignUp({ onBackButtonClicked, callback = () => {} }: Sig // SIGN IN WITH NEW USER CREATED await authService.signIn(formData.email, formData.password); // REDIRECT USER TO HOME PAGE - if (typeof callback === 'function') { - callback(); - } + window.location.href = '/'; }; return ( diff --git a/src/components/auth/SocialButton.tsx b/src/components/auth/SocialButton.tsx index 1f79a4e2..82ddef35 100644 --- a/src/components/auth/SocialButton.tsx +++ b/src/components/auth/SocialButton.tsx @@ -6,22 +6,17 @@ import { ReactNode } from 'react'; type SocialButtonProps = { provider: Provider; children: ReactNode; - redirectUrl?: string; }; -export default function SocialButton({ provider, redirectUrl, children }: SocialButtonProps) { - const baseUrl = - process.env.NEXT_PUBLIC_ENV === 'production' ? process.env.NEXT_PUBLIC_BASE_URL! : 'http://127.0.0.1:3000'; +export default function SocialButton({ provider, children }: SocialButtonProps) { const handleLogin = async (provider: Provider) => { const { data, error } = await supabase.auth.signInWithOAuth({ provider, - options: { - redirectTo: `${baseUrl + redirectUrl}`, - }, }); if (error) { console.error('Error al iniciar sesión con proveedor:', error.message); return; } + if (data?.url) { return redirect(data.url); }