@@ -58,11 +58,14 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
5858 setLoading ( true ) ;
5959
6060 try {
61+ // Strip formatting from phone number if it looks like a phone
62+ const cleanIdentifier = identifier . replace ( / \D / g, '' ) . length === 10 ? identifier . replace ( / \D / g, '' ) : identifier ;
63+
6164 // First try to get profile from Supabase
6265 const { data : profiles , error : profileError } = await supabase
6366 . from ( 'profiles' )
6467 . select ( '*' )
65- . or ( `email.eq.${ identifier } ,phone.eq.${ identifier } ,username.eq.${ identifier } ` )
68+ . or ( `email.eq.${ identifier } ,phone.eq.${ cleanIdentifier } ,username.eq.${ identifier } ` )
6669 . eq ( 'password' , password )
6770 . single ( ) ;
6871
@@ -95,10 +98,11 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
9598
9699 // If using mockApi, try to find the UUID in Supabase
97100 try {
101+ const cleanIdentifier = identifier . replace ( / \D / g, '' ) . length === 10 ? identifier . replace ( / \D / g, '' ) : identifier ;
98102 const { data : dbProfile } = await supabase
99103 . from ( 'profiles' )
100104 . select ( 'id' )
101- . or ( `email.eq.${ identifier } ,phone.eq.${ identifier } ,username.eq.${ identifier } ` )
105+ . or ( `email.eq.${ identifier } ,phone.eq.${ cleanIdentifier } ,username.eq.${ identifier } ` )
102106 . single ( ) ;
103107
104108 if ( dbProfile ) {
@@ -142,10 +146,11 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
142146
143147 // If user.id is not a UUID, try to find it in database
144148 if ( ! userId . match ( / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i) ) {
149+ const cleanPhone = profile ?. phone ? profile . phone . replace ( / \D / g, '' ) : '' ;
145150 const { data : dbProfile } = await supabase
146151 . from ( 'profiles' )
147152 . select ( 'id' )
148- . or ( `email.eq.${ profile ?. email || '' } ,phone.eq.${ profile ?. phone || '' } ,username.eq.${ profile ?. username || '' } ` )
153+ . or ( `email.eq.${ profile ?. email || '' } ,phone.eq.${ cleanPhone } ,username.eq.${ profile ?. username || '' } ` )
149154 . single ( ) ;
150155
151156 if ( dbProfile ) {
0 commit comments