@@ -5,6 +5,11 @@ import login_img from "../assets/images/golden_retriever.jpg"
5
5
import signup_img from "../assets/images/golden_retriever_2.jpg"
6
6
import { motion as framer , useWillChange } from 'framer-motion'
7
7
import AuthInput from '../components/AuthInput'
8
+ import { createUserWithEmailAndPassword , signInWithEmailAndPassword } from 'firebase/auth'
9
+ import { firebaseAuth } from '../others/FirebaseConfig'
10
+ import google_icon from '../assets/images/google_icon.png'
11
+ import facebook_icon from '../assets/images/facebook_icon.png'
12
+ import tiktok_icon from '../assets/images/tiktok_icon.png'
8
13
9
14
export enum INPUT_ID {
10
15
LOGIN_EMAIL ,
@@ -39,6 +44,41 @@ const AuthPage: React.FC = () => {
39
44
}
40
45
}
41
46
47
+ const loginHandler = async ( _ : React . MouseEvent ) : Promise < void > => {
48
+ const email = m_inputData [ INPUT_ID . LOGIN_EMAIL ]
49
+ const pwd = m_inputData [ INPUT_ID . LOGIN_PASSWORD ]
50
+
51
+ signInWithEmailAndPassword ( firebaseAuth , email , pwd )
52
+ . then ( userCreds => {
53
+ console . log ( "Successfully login with the user: " , userCreds . user , ". Redirecting...." )
54
+ // TODO - SetTimeout
55
+ } )
56
+ . catch ( err => {
57
+ console . log ( "Unable to log the user in, exited with error code: " , err . code )
58
+ console . log ( "Error message: " , err . message )
59
+ } )
60
+ }
61
+
62
+ const signupHandler = async ( _ : React . MouseEvent ) : Promise < void > => {
63
+ const email = m_inputData [ INPUT_ID . SIGNUP_EMAIL ]
64
+ const pwd = m_inputData [ INPUT_ID . SIGNUP_PASSWORD ]
65
+ const confirmPwd = m_inputData [ INPUT_ID . SIGNUP_CONFIRM_PASSWORD ]
66
+
67
+ if ( pwd !== confirmPwd ) {
68
+ console . log ( "Passwords do not match" )
69
+ return
70
+ }
71
+
72
+ createUserWithEmailAndPassword ( firebaseAuth , email , pwd )
73
+ . then ( userCreds => {
74
+ console . log ( "Successfully signed up the user: " , userCreds . user , ". Proceed to sign in" )
75
+ } )
76
+ . catch ( err => {
77
+ console . log ( "Unable to sign up with credentials, exited with error code: " , err . code )
78
+ console . log ( "Error message: " , err . message )
79
+ } )
80
+ }
81
+
42
82
return (
43
83
< main >
44
84
< Navbar useSticky = { true } />
@@ -61,7 +101,7 @@ const AuthPage: React.FC = () => {
61
101
className = 'hidden md:block bg-cover h-full w-[99rem] rounded-l-2xl' >
62
102
</ div >
63
103
64
- < form onSubmit = { e => e . preventDefault ( ) } className = 'flex justify-center items-center min-w-[24rem ] xl:min-w-[28rem ] px-10' >
104
+ < form onSubmit = { e => e . preventDefault ( ) } className = 'flex justify-center items-center min-w-[28rem ] xl:min-w-[34rem ] px-10' >
65
105
< div className = 'w-full flex flex-col justify-start items-center' >
66
106
{
67
107
< button onClick = { toggleClickHandler }
@@ -75,7 +115,7 @@ const AuthPage: React.FC = () => {
75
115
< h2 className = 'font-bold text-3xl mb-text-m' > LOGIN</ h2 >
76
116
< AuthInput inputID = { INPUT_ID . LOGIN_EMAIL } inputType = 'email' placeholder = 'Email' inputData = { m_inputData } setInputData = { setInputData } />
77
117
< AuthInput inputID = { INPUT_ID . LOGIN_PASSWORD } inputType = 'password' placeholder = 'Password' inputData = { m_inputData } setInputData = { setInputData } />
78
- < button className = '
118
+ < button onClick = { loginHandler } className = '
79
119
w-full py-3 rounded-lg transition-colors bg-primary-500 hover:bg-primary-600 mb-margin-l
80
120
' > Login</ button >
81
121
</ >
@@ -85,7 +125,7 @@ const AuthPage: React.FC = () => {
85
125
< AuthInput inputID = { INPUT_ID . SIGNUP_EMAIL } inputType = 'email' placeholder = 'Email' inputData = { m_inputData } setInputData = { setInputData } />
86
126
< AuthInput inputID = { INPUT_ID . SIGNUP_PASSWORD } inputType = 'password' placeholder = 'Password' inputData = { m_inputData } setInputData = { setInputData } />
87
127
< AuthInput inputID = { INPUT_ID . SIGNUP_CONFIRM_PASSWORD } inputType = 'password' inputData = { m_inputData } placeholder = 'Confirm Password' setInputData = { setInputData } />
88
- < button className = '
128
+ < button onClick = { signupHandler } className = '
89
129
w-full py-3 rounded-lg transition-colors bg-primary-500 hover:bg-primary-600 mb-margin-l
90
130
' > Sign up</ button >
91
131
</ >
@@ -109,10 +149,29 @@ const AuthPage: React.FC = () => {
109
149
< div className = 'w-full h-[1px] bg-gray-400' > </ div >
110
150
</ div >
111
151
112
- < div className = 'w-full flex justify-around' >
113
- < button > X</ button >
114
- < button > G</ button >
115
- < button > L</ button >
152
+ { /* --- ALTERNATIVE SIGN-INS --- */ }
153
+ < div className = 'w-full flex justify-center text-sm gap-4' >
154
+ < button className = '
155
+ flex justify-center items-center h-11 rounded-lg bg-background-900
156
+ hover:bg-background-800 transition-colors duration-200 w-32
157
+ ' >
158
+ < img className = 'w-5 h-5 mr-margin-s' src = { google_icon } alt = "" />
159
+ < span > Google</ span >
160
+ </ button >
161
+ < button className = '
162
+ flex justify-center items-center h-11 rounded-lg bg-background-900
163
+ hover:bg-background-800 transition-colors duration-200 w-32
164
+ ' >
165
+ < img className = 'w-5 h-5 mr-margin-s' src = { facebook_icon } alt = "" />
166
+ < span > Facebook</ span >
167
+ </ button >
168
+ < button className = '
169
+ flex justify-center items-center h-11 rounded-lg bg-background-900
170
+ hover:bg-background-800 transition-colors duration-200 w-32
171
+ ' >
172
+ < img className = 'w-5 h-5 mr-margin-s' src = { tiktok_icon } alt = "" />
173
+ < span > TikTok</ span >
174
+ </ button >
116
175
</ div >
117
176
</ div >
118
177
</ form >
0 commit comments