Skip to content

Commit

Permalink
fix: check if user is already connected - if true then redirect him t… (
Browse files Browse the repository at this point in the history
#135)

* fix: check if user is already connected - if true then redirect him to /user else do nothing

* fix: modified to Redirecting
  • Loading branch information
Freshenext authored Aug 27, 2024
1 parent 085f6f1 commit 4acc573
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/app/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Logo } from '@/components/Header/Logo'
import { cn } from '@/lib/utils'
import { useRouter } from 'next/navigation'
import { useEffect, useState } from 'react'
import { FaLink, FaUsers } from 'react-icons/fa6'
import { useAccount, useDisconnect } from 'wagmi'
import { FaUsers } from 'react-icons/fa6'
import { useAccount } from 'wagmi'
import { LoadingSpinner } from '@/components/LoadingSpinner'

const BACKGROUND_CLASSES = 'bg-[url(../../public/images/login-bg.svg)] bg-cover'

export const Login = () => {
const { isConnected, address } = useAccount()
const { disconnect } = useDisconnect()
const [hasMounted, setHasMounted] = useState(false)

const router = useRouter()
Expand All @@ -25,29 +25,31 @@ export const Login = () => {
setHasMounted(true)
}, [])

useEffect(() => {
// Redirect the user to /user if connected
if (isConnected) {
router.push('/user')
}
}, [isConnected])
return (
<div className={cn(BACKGROUND_CLASSES, 'flex flex-col justify-center items-center h-screen')}>
<Logo className="mb-8" textClassName="text-6xl" />
<div className="flex space-x-4">
{hasMounted && (
<>
{isConnected ? (
<Button
onClick={() => disconnect()}
variant="secondary"
className="border-red-600"
textClassName="text-red-600"
startIcon={<FaLink />}
>
Disconnect
</Button>
<div className="flex flex-col items-center">
<p>Redirecting...</p>
<LoadingSpinner />
</div>
) : (
<ConnectButton onSuccess={() => router.push('/user')} />
<>
<ConnectButton onSuccess={() => router.push('/user')} />
<Button onClick={handleExploreCommunities} variant="secondary" startIcon={<FaUsers />}>
Explore Communities
</Button>
</>
)}

<Button onClick={handleExploreCommunities} variant="secondary" startIcon={<FaUsers />}>
Explore Communities
</Button>
</>
)}
</div>
Expand Down

0 comments on commit 4acc573

Please sign in to comment.