@@ -4,15 +4,15 @@ import PhoneInputWithCountryCode from '@/components/phoneInput';
44import { useInternalAuth } from '@/context/InternalAuthContext' ;
55import React , { useEffect , useState } from 'react' ;
66import { useNavigate } from 'react-router-dom' ;
7-
7+ import { login } from '../utils' ;
88import styles from '@/styles/login.module.css' ;
99import { isPasskeySupported , isValidEmail , isValidPhoneNumber } from '../utils' ;
1010import { createFetchWithAuth } from '@/fetchWithAuth' ;
1111import AuthFallbackOptions from '@/components/AuthFallbackOptions' ;
1212
1313const Login : React . FC = ( ) => {
1414 const navigate = useNavigate ( ) ;
15- const { apiHost, hasSignedInBefore, mode : authMode } = useAuth ( ) ;
15+ const { apiHost, hasSignedInBefore, mode : authMode , fetchWithAuth } = useAuth ( ) ;
1616 const { validateToken } = useInternalAuth ( ) ;
1717 const [ identifier , setIdentifier ] = useState < string > ( '' ) ;
1818 const [ email , setEmail ] = useState < string > ( '' ) ;
@@ -25,15 +25,17 @@ const Login: React.FC = () => {
2525 const [ passkeyAvailable , setPasskeyAvailable ] = useState ( false ) ;
2626 const [ showFallbackOptions , setShowFallbackOptions ] = useState ( false ) ;
2727
28- const fetchWithAuth = createFetchWithAuth ( {
29- authMode,
30- authHost : apiHost ,
31- } ) ;
28+ // const fetchWithAuth = createFetchWithAuth({
29+ // authMode,
30+ // authHost: apiHost,
31+ // });
3232
3333 useEffect ( ( ) => {
3434 async function checkSupport ( ) {
3535 const supported = await isPasskeySupported ( ) ;
36+ // console.log('checking passkey', supported);
3637 setPasskeyAvailable ( supported ) ;
38+ console . log ( 'checking passkey' , supported ) ;
3739 }
3840
3941 checkSupport ( ) ;
@@ -102,32 +104,6 @@ const Login: React.FC = () => {
102104 }
103105 } ;
104106
105- const login = async ( ) => {
106- setFormErrors ( '' ) ;
107-
108- const response = await fetchWithAuth ( `/login` , {
109- method : 'POST' ,
110- body : JSON . stringify ( { identifier, passkeyAvailable } ) ,
111- } ) ;
112-
113- if ( ! response . ok ) {
114- setFormErrors ( 'Failed to send login link. Please try again.' ) ;
115- return ;
116- }
117-
118- if ( ! passkeyAvailable ) {
119- setShowFallbackOptions ( true ) ;
120- return ;
121- }
122-
123- try {
124- await handlePasskeyLogin ( ) ;
125- } catch ( err ) {
126- console . error ( 'Passkey login failed' , err ) ;
127- setShowFallbackOptions ( true ) ;
128- }
129- } ;
130-
131107 const register = async ( ) => {
132108 setFormErrors ( '' ) ;
133109
@@ -198,7 +174,14 @@ const Login: React.FC = () => {
198174 const handleSubmit = async ( e : React . FormEvent < HTMLFormElement > ) => {
199175 e . preventDefault ( ) ;
200176
201- if ( mode === 'login' ) login ( ) ;
177+ if ( mode === 'login' ) {
178+ if ( passkeyAvailable ) {
179+ const res = login ( fetchWithAuth , identifier , passkeyAvailable ) ;
180+ } else {
181+ setShowFallbackOptions ( true ) ;
182+ console . log ( setShowFallbackOptions ) ;
183+ }
184+ }
202185 if ( mode === 'register' ) register ( ) ;
203186 } ;
204187
0 commit comments