@@ -10,6 +10,8 @@ import {
10
10
Pressable ,
11
11
AppState ,
12
12
Alert ,
13
+ ActivityIndicator ,
14
+ ScrollView ,
13
15
} from "react-native" ;
14
16
import { Ionicons } from "@expo/vector-icons" ;
15
17
import CheckBox from "expo-checkbox" ;
@@ -20,12 +22,10 @@ import { Colors } from "../../../constants/Colors";
20
22
import { ThemeContext } from "@/ctx/ThemeContext" ;
21
23
import { SvgXml } from "react-native-svg" ;
22
24
import {
23
- BackArrow ,
24
25
BlackApple ,
25
26
DarkContinueLine ,
26
27
LightContinueLine ,
27
28
WhiteApple ,
28
- blackArrow ,
29
29
} from "@/components/Icons/Icons" ;
30
30
import Alerts from "@/components/UI/AlertComponent" ;
31
31
import { StatusBar } from "expo-status-bar" ;
@@ -34,6 +34,7 @@ import * as WebBrowser from "expo-web-browser";
34
34
import * as Linking from "expo-linking" ;
35
35
import { makeRedirectUri } from "expo-auth-session" ;
36
36
import * as QueryParams from "expo-auth-session/build/QueryParams" ;
37
+ import { useAuth } from "@/ctx/AuthContext" ;
37
38
38
39
WebBrowser . maybeCompleteAuthSession ( ) ;
39
40
const redirectTo = makeRedirectUri ( {
@@ -90,24 +91,21 @@ AppState.addEventListener("change", (state) => {
90
91
} ) ;
91
92
92
93
const Login = ( ) => {
93
- // const {login, loading} = useContext(AuthContext)
94
-
94
+ const { login } = useAuth ( ) ;
95
95
const [ email , setEmail ] = useState ( "" ) ;
96
96
const [ password , setPassword ] = useState ( "" ) ;
97
- const [ loading , setLoading ] = useState ( false ) ;
97
+ // const [loading, setLoading] = useState(false)
98
98
const [ secureTextEntry , setSecureTextEntry ] = useState ( true ) ;
99
99
const [ isChecked , setIsChecked ] = useState ( false ) ;
100
100
const [ emailFocused , setEmailFocused ] = useState ( false ) ;
101
101
const [ passwordFocused , setPasswordFocused ] = useState ( false ) ;
102
102
const { theme, changeTheme } = useContext ( ThemeContext ) ;
103
- const [ alert , setAlert ] = useState < { text : string , status : "success" | "error" | "info" | "warning" } | null > ( null ) ;
104
- const handleEmailChange = ( text : string ) => {
105
- setEmail ( text ) ;
106
- } ;
107
103
108
- const handlePasswordChange = ( text : string ) => {
109
- setPassword ( text ) ;
110
- } ;
104
+ const url = Linking . useURL ( ) ;
105
+ console . log ( { url } ) ;
106
+ if ( url ) createSessionFromUrl ( url ) ;
107
+
108
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
111
109
112
110
const togglePasswordVisibility = ( ) => {
113
111
setSecureTextEntry ( ! secureTextEntry ) ;
@@ -131,33 +129,36 @@ const Login = () => {
131
129
setPasswordFocused ( false ) ;
132
130
} ;
133
131
134
- async function signInWithEmail ( ) {
135
- setLoading ( true )
136
- const { error} = await supabase . auth . signInWithPassword ( {
137
- email : email ,
138
- password : password ,
139
- } )
140
- if ( error ) {
141
- setAlert ( { text : "invalid email or password" , status : "error" } ) ;
142
- setLoading ( false ) ;
143
132
144
- } else {
145
- setAlert ( { text : "login successfully" , status : "success" } ) ;
146
- router . push ( '(app)/ActionMenu' ) ;
147
- setLoading ( false ) ;
148
-
149
- } }
133
+ async function signInWithEmail ( ) {
134
+ try {
135
+ setIsLoading ( true ) ;
136
+ await login ( email , password ) ;
137
+ } catch ( error ) {
138
+ Alert . alert ( "Error signing in" ) ;
139
+ setIsLoading ( false ) ;
140
+ }
141
+ }
150
142
151
143
return (
152
- < View
153
- style = { [
154
- styles . container ,
155
- { backgroundColor : theme === "dark" ? "#181A20" : "#FFFFFF" } ,
156
- ] }
144
+ < ScrollView
145
+ style = { {
146
+ backgroundColor : theme === "dark" ? "#181A20" : "#FFFFFF" ,
147
+ flex : 1 ,
148
+ } }
149
+ contentContainerStyle = { {
150
+ flexGrow : 1 ,
151
+ justifyContent : "center" ,
152
+ alignItems : "center" ,
153
+ paddingTop : 24 ,
154
+ paddingLeft : 24 ,
155
+ paddingRight : 24 ,
156
+ paddingBottom : 48 ,
157
+ gap : 17 ,
158
+ } }
157
159
>
158
-
159
160
< StatusBar style = { theme === "dark" ? "light" : "dark" } />
160
-
161
+
161
162
< View >
162
163
< Image source = { require ( "../../../assets/icons/HeartPlus.png" ) } />
163
164
</ View >
@@ -171,7 +172,6 @@ async function signInWithEmail(){
171
172
>
172
173
Login to Your Account
173
174
</ Text >
174
- { alert && < Alerts text = { alert . text } status = { alert . status } /> }
175
175
</ View >
176
176
177
177
< View style = { styles . Buttons } >
@@ -190,7 +190,14 @@ async function signInWithEmail(){
190
190
style = { [ styles . icon , emailFocused && styles . iconFocused ] }
191
191
/>
192
192
< TextInput
193
- style = { [ { fontSize : 16 , flex : 1 , color : theme === "dark" ? Colors . grayScale . _50 : "black" } , emailFocused && styles . emailFocused ] }
193
+ style = { [
194
+ {
195
+ fontSize : 16 ,
196
+ flex : 1 ,
197
+ color : theme === "dark" ? Colors . grayScale . _50 : "black" ,
198
+ } ,
199
+ emailFocused && styles . emailFocused ,
200
+ ] }
194
201
placeholder = "Email"
195
202
keyboardType = "email-address"
196
203
placeholderTextColor = "#9E9E9E"
@@ -217,7 +224,14 @@ async function signInWithEmail(){
217
224
/>
218
225
219
226
< TextInput
220
- style = { [ { fontSize : 16 , flex : 1 , color : theme === "dark" ? Colors . grayScale . _50 : "black" } , passwordFocused && styles . emailFocused ] }
227
+ style = { [
228
+ {
229
+ fontSize : 16 ,
230
+ flex : 1 ,
231
+ color : theme === "dark" ? Colors . grayScale . _50 : "black" ,
232
+ } ,
233
+ passwordFocused && styles . emailFocused ,
234
+ ] }
221
235
placeholder = "Password"
222
236
placeholderTextColor = "#9E9E9E"
223
237
secureTextEntry = { secureTextEntry }
@@ -262,13 +276,28 @@ async function signInWithEmail(){
262
276
</ View >
263
277
264
278
< View >
265
- < TouchableOpacity
266
- disabled = { loading }
279
+ < Pressable
280
+ disabled = { isLoading }
267
281
onPress = { ( ) => signInWithEmail ( ) }
268
- style = { styles . signinBtn }
282
+ style = { {
283
+ backgroundColor : isLoading
284
+ ? Colors . status . disabled_button
285
+ : Colors . main . primary . _500 ,
286
+ width : 360 ,
287
+ height : 58 ,
288
+ borderRadius : 100 ,
289
+ justifyContent : "center" ,
290
+ alignItems : "center" ,
291
+ shadowColor : "#246BFD" ,
292
+ elevation : 10 ,
293
+ } }
269
294
>
270
- < Text style = { styles . signText } > Sign in</ Text >
271
- </ TouchableOpacity >
295
+ { isLoading ? (
296
+ < ActivityIndicator color = "white" />
297
+ ) : (
298
+ < Text style = { styles . signText } > Sign in</ Text >
299
+ ) }
300
+ </ Pressable >
272
301
</ View >
273
302
274
303
< TouchableOpacity
@@ -353,12 +382,10 @@ async function signInWithEmail(){
353
382
Sign up
354
383
</ Text >
355
384
</ View >
356
- </ View >
385
+ </ ScrollView >
357
386
) ;
358
387
} ;
359
388
360
- export default Login ;
361
-
362
389
const styles = StyleSheet . create ( {
363
390
inputOneFocused : {
364
391
borderColor : "#246BFD" ,
@@ -455,16 +482,6 @@ const styles = StyleSheet.create({
455
482
color : "#FFFFFF" ,
456
483
fontWeight : "bold" ,
457
484
} ,
458
- signinBtn : {
459
- backgroundColor : "#246BFD" ,
460
- width : 360 ,
461
- height : 58 ,
462
- borderRadius : 100 ,
463
- justifyContent : "center" ,
464
- alignItems : "center" ,
465
- shadowColor : "#246BFD" ,
466
- elevation : 10 ,
467
- } ,
468
485
textBtn : {
469
486
fontSize : 16 ,
470
487
fontWeight : "bold" ,
@@ -510,17 +527,11 @@ const styles = StyleSheet.create({
510
527
} ,
511
528
container : {
512
529
flex : 1 ,
513
- flexDirection : "column" ,
514
- justifyContent : "center" ,
515
- alignItems : "center" ,
516
- gap : 17 ,
517
- paddingTop : 24 ,
518
- paddingLeft : 24 ,
519
- paddingBottom : 48 ,
520
- paddingRight : 24 ,
521
530
} ,
522
531
LoginText : {
523
532
color : "#246BFD" ,
524
533
fontWeight : "600" ,
525
534
} ,
526
535
} ) ;
536
+
537
+ export default Login ;
0 commit comments