11'use client' ;
2- import { useState } from 'react' ;
2+ import { useEffect , useState } from 'react' ;
33import { Button } from '@/components/ui/button' ;
44import { Checkbox } from '@/components/ui/checkbox' ;
55import { Input } from '@/components/ui/input' ;
66import Link from 'next/link' ;
77import { GithubIcon } from 'lucide-react' ;
8- import { Alert , AlertDescription , AlertTitle } from '@/components/ui/alert' ;
8+ import { Alert , AlertDescription } from '@/components/ui/alert' ;
99import { axiosClient } from '@/network/axiosClient' ;
1010import { login } from '@/lib/auth' ;
1111import { useRouter } from 'next/navigation' ;
1212import { useAuthStore } from '@/state/useAuthStore' ;
13+ import { initiateOAuth } from '@/lib/oauth' ;
1314
14- export default function LoginForm ( ) {
15+ // Add Props type for the page
16+ type Props = {
17+ searchParams : { [ key : string ] : string | string [ ] | undefined } ;
18+ } ;
19+
20+ export default function LoginForm ( { searchParams } : Props ) {
1521 const [ email , setEmail ] = useState ( '' ) ;
1622 const [ password , setPassword ] = useState ( '' ) ;
1723 const [ error , setError ] = useState ( '' ) ;
1824 const router = useRouter ( ) ;
1925 const setAuth = useAuthStore ( ( state ) => state . setAuth ) ;
2026
27+ useEffect ( ( ) => {
28+ const error = searchParams ?. error ;
29+ if ( error ) {
30+ setError ( 'email or username already exists' ) ;
31+ }
32+ } , [ searchParams ] ) ;
33+
2134 // handle login here
2235 const handleLogin = async ( e : React . FormEvent ) => {
2336 e . preventDefault ( ) ;
@@ -40,12 +53,15 @@ export default function LoginForm() {
4053 setError ( data . error || 'Please provide correct email and password' ) ;
4154 } ;
4255
56+ const handleGithubLogin = ( ) => {
57+ initiateOAuth ( 'github' ) ;
58+ } ;
59+
4360 return (
4461 < div className = "flex min-h-screen items-center justify-center bg-gray-900" >
4562 < div className = "w-full max-w-md space-y-6 rounded-lg bg-gray-800 p-8 shadow-xl" >
4663 { error && (
4764 < Alert variant = "destructive" className = "mb-4" >
48- < AlertTitle > Error</ AlertTitle >
4965 < AlertDescription > { error } </ AlertDescription >
5066 </ Alert >
5167 ) }
@@ -100,32 +116,21 @@ export default function LoginForm() {
100116 </ span >
101117 </ div >
102118 </ div >
103- < div className = "grid grid-cols-2 gap-3" >
119+ < div className = "flex w-full justify-center gap-3" >
104120 < Button
105121 variant = "outline"
106122 className = "rounded-md border border-gray-600 bg-gray-700 py-2 text-sm font-medium text-white hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-800"
123+ onClick = { handleGithubLogin }
107124 >
108125 < GithubIcon className = "mr-2 h-5 w-5" />
109126 GitHub
110127 </ Button >
111- < Button
112- variant = "outline"
113- className = "rounded-md border border-gray-600 bg-gray-700 py-2 text-sm font-medium text-white hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-800"
114- >
115- < svg className = "mr-2 h-5 w-5" viewBox = "0 0 24 24" >
116- < path
117- fill = "currentColor"
118- d = "M12.545,10.239v3.821h5.445c-0.712,2.315-2.647,3.972-5.445,3.972c-3.332,0-6.033-2.701-6.033-6.032s2.701-6.032,6.033-6.032c1.498,0,2.866,0.549,3.921,1.453l2.814-2.814C17.503,2.988,15.139,2,12.545,2C7.021,2,2.543,6.477,2.543,12s4.478,10,10.002,10c8.396,0,10.249-7.85,9.426-11.748L12.545,10.239z"
119- />
120- </ svg >
121- Google
122- </ Button >
123128 </ div >
124129 < div className = "flex justify-center text-center text-sm text-gray-400" >
125130 Do not have an account?
126131 < span className = "mx-1" />
127132 < Link href = "/signup" className = "text-blue-500 hover:underline" >
128- Sign up
133+ Sign up with email
129134 </ Link >
130135 </ div >
131136 </ div >
0 commit comments