1
1
import React from "react" ;
2
- import { StyleSheet , Text , Dimensions , TouchableOpacity } from "react-native" ;
2
+ import { StyleSheet , Text , Dimensions , TouchableOpacity } from "react-native" ;
3
3
import { FirebaseError } from "firebase/app" ;
4
4
import { User } from "firebase/auth" ;
5
5
6
6
//Type to handle Authentication Responses from firebase
7
- export type AuthenticationResponse = {
8
- user : User | null ;
9
- error ?: undefined ;
10
- } | {
11
- user ?: undefined ;
12
- error : unknown ;
13
- }
7
+ export type AuthenticationResponse =
8
+ | {
9
+ user : User | null ;
10
+ error ?: undefined ;
11
+ }
12
+ | {
13
+ user ?: undefined ;
14
+ error : unknown ;
15
+ } ;
14
16
15
17
export class CustomError {
16
18
public code : string ;
@@ -23,7 +25,10 @@ export class CustomError {
23
25
}
24
26
25
27
//Custom responses
26
- export const inValidEmailResponse = new CustomError ( "Invalid Email" , "Please provide a valid email address" )
28
+ export const inValidEmailResponse = new CustomError (
29
+ "Invalid Email" ,
30
+ "Please provide a valid email address"
31
+ ) ;
27
32
28
33
//Function that decodes the error code
29
34
const decodeFirebaseError = ( error : FirebaseError ) => {
@@ -47,54 +52,56 @@ const decodeFirebaseError = (error: FirebaseError) => {
47
52
48
53
const decodeCustomError = ( error : CustomError ) => {
49
54
return error . message ;
50
- }
55
+ } ;
51
56
52
57
//Function that handles the response depending on type
53
- function handleResponse ( response : AuthenticationResponse ) {
54
- if ( response ?. user ) {
58
+ const handleResponse = ( response : AuthenticationResponse ) => {
59
+ if ( response ?. user ) {
60
+ // If the user is not undefined
55
61
return "" ;
56
62
}
57
63
58
- console . log ( response . error )
59
-
60
- if ( response . error instanceof FirebaseError ) {
64
+ if ( response . error instanceof FirebaseError ) {
65
+ // If the error is a firebase error
61
66
return decodeFirebaseError ( response . error ) ;
62
67
}
63
-
64
- if ( response . error instanceof CustomError ) {
68
+ // If the error is a custom error
69
+ if ( response . error instanceof CustomError ) {
70
+ // If the error is a custom error
65
71
return decodeCustomError ( response . error ) ;
66
72
}
67
73
68
- return "Unknown error"
69
- }
74
+ return "Unknown error" ;
75
+ } ;
70
76
71
- //Something
77
+ // Authentication Message Component Props
72
78
interface AuthenticationErrorMessageProps {
73
79
response : AuthenticationResponse | undefined ;
74
80
onPress ?: ( ) => void ;
75
81
}
76
82
77
- export const AuthenticationErrorMessage : React . FC < AuthenticationErrorMessageProps > = ( { response, onPress } ) => {
78
- if ( response === undefined ) {
83
+ export const AuthenticationErrorMessage : React . FC <
84
+ AuthenticationErrorMessageProps
85
+ > = ( { response, onPress } ) => {
86
+ if ( response === undefined ) {
79
87
return null ;
80
88
}
81
89
82
- const errorMessage = handleResponse ( response )
90
+ const errorMessage = handleResponse ( response ) ;
83
91
84
92
return (
85
- errorMessage &&
86
- < TouchableOpacity style = { styles . error_container } onPressIn = { onPress } >
93
+ errorMessage && (
94
+ < TouchableOpacity style = { styles . error_container } onPressIn = { onPress } >
87
95
< Text style = { styles . error_text } > { errorMessage } </ Text >
88
- </ TouchableOpacity >
96
+ </ TouchableOpacity >
97
+ )
89
98
) ;
90
- }
91
-
99
+ } ;
92
100
93
101
const styles = StyleSheet . create ( {
94
102
error_text : {
95
103
color : "white" ,
96
104
fontSize : Dimensions . get ( "window" ) . height * 0.02 ,
97
-
98
105
} ,
99
106
error_container : {
100
107
display : "flex" ,
@@ -105,7 +112,6 @@ const styles = StyleSheet.create({
105
112
marginTop : Dimensions . get ( "window" ) . height * 0.005 ,
106
113
width : Dimensions . get ( "window" ) . width * 0.9 ,
107
114
borderRadius : 10 ,
108
- padding : 10
109
- }
115
+ padding : 10 ,
116
+ } ,
110
117
} ) ;
111
-
0 commit comments