@@ -4,15 +4,20 @@ import PhoneInputWithCountryCode from '@/components/phoneInput';
44import { useInternalAuth } from '@/context/InternalAuthContext' ;
55import React , { useEffect , useState } from 'react' ;
66import { useNavigate } from 'react-router-dom' ;
7- import { login } from '../utils' ;
87import styles from '@/styles/login.module.css' ;
98import { isPasskeySupported , isValidEmail , isValidPhoneNumber } from '../utils' ;
109import { createFetchWithAuth } from '@/fetchWithAuth' ;
1110import AuthFallbackOptions from '@/components/AuthFallbackOptions' ;
1211
1312const Login : React . FC = ( ) => {
1413 const navigate = useNavigate ( ) ;
15- const { apiHost, hasSignedInBefore, mode : authMode , fetchWithAuth } = useAuth ( ) ;
14+ const {
15+ apiHost,
16+ hasSignedInBefore,
17+ mode : authMode ,
18+ login,
19+ handlePasskeyLogin,
20+ } = useAuth ( ) ;
1621 const { validateToken } = useInternalAuth ( ) ;
1722 const [ identifier , setIdentifier ] = useState < string > ( '' ) ;
1823 const [ email , setEmail ] = useState < string > ( '' ) ;
@@ -25,10 +30,10 @@ const Login: React.FC = () => {
2530 const [ passkeyAvailable , setPasskeyAvailable ] = useState ( false ) ;
2631 const [ showFallbackOptions , setShowFallbackOptions ] = useState ( false ) ;
2732
28- // const fetchWithAuth = createFetchWithAuth({
29- // authMode,
30- // authHost: apiHost,
31- // });
33+ const fetchWithAuth = createFetchWithAuth ( {
34+ authMode,
35+ authHost : apiHost ,
36+ } ) ;
3237
3338 useEffect ( ( ) => {
3439 async function checkSupport ( ) {
@@ -63,46 +68,46 @@ const Login: React.FC = () => {
6368 return isValidEmail ( email ) && isValidPhoneNumber ( phone ) ;
6469 } ;
6570
66- const handlePasskeyLogin = async ( ) => {
67- try {
68- const response = await fetchWithAuth ( `/webAuthn/login/start` , {
69- method : 'POST' ,
70- } ) ;
71-
72- if ( ! response . ok ) {
73- console . error ( 'Something went wrong getting webauthn options' ) ;
74- return ;
75- }
76-
77- const options = await response . json ( ) ;
78- const credential = await startAuthentication ( { optionsJSON : options } ) ;
79-
80- const verificationResponse = await fetchWithAuth ( `/webAuthn/login/finish` , {
81- method : 'POST' ,
82- body : JSON . stringify ( { assertionResponse : credential } ) ,
83- } ) ;
84-
85- if ( ! verificationResponse . ok ) {
86- console . error ( 'Failed to verify passkey' ) ;
87- }
88-
89- const verificationResult = await verificationResponse . json ( ) ;
90-
91- if ( verificationResult . message === 'Success' ) {
92- if ( verificationResult . mfaLogin ) {
93- navigate ( '/mfaLogin' ) ;
94- return ;
95- }
96- await validateToken ( ) ;
97- navigate ( '/' ) ;
98- return ;
99- } else {
100- console . error ( 'Passkey login failed:' , verificationResult . message ) ;
101- }
102- } catch ( error ) {
103- console . error ( 'Passkey login error:' , error ) ;
104- }
105- } ;
71+ // const handlePasskeyLogin = async () => {
72+ // try {
73+ // const response = await fetchWithAuth(`/webAuthn/login/start`, {
74+ // method: 'POST',
75+ // });
76+
77+ // if (!response.ok) {
78+ // console.error('Something went wrong getting webauthn options');
79+ // return;
80+ // }
81+
82+ // const options = await response.json();
83+ // const credential = await startAuthentication({ optionsJSON: options });
84+
85+ // const verificationResponse = await fetchWithAuth(`/webAuthn/login/finish`, {
86+ // method: 'POST',
87+ // body: JSON.stringify({ assertionResponse: credential }),
88+ // });
89+
90+ // if (!verificationResponse.ok) {
91+ // console.error('Failed to verify passkey');
92+ // }
93+
94+ // const verificationResult = await verificationResponse.json();
95+
96+ // if (verificationResult.message === 'Success') {
97+ // if (verificationResult.mfaLogin) {
98+ // navigate('/mfaLogin');
99+ // return;
100+ // }
101+ // await validateToken();
102+ // navigate('/');
103+ // return;
104+ // } else {
105+ // console.error('Passkey login failed:', verificationResult.message);
106+ // }
107+ // } catch (error) {
108+ // console.error('Passkey login error:', error);
109+ // }
110+ // };
106111
107112 const register = async ( ) => {
108113 setFormErrors ( '' ) ;
@@ -136,7 +141,7 @@ const Login: React.FC = () => {
136141
137142 const sendMagicLink = async ( ) => {
138143 try {
139- const response = await fetchWithAuth ( `/magic-link ` , {
144+ const response = await fetchWithAuth ( `/magiclinks ` , {
140145 method : 'GET' ,
141146 } ) ;
142147
@@ -145,7 +150,7 @@ const Login: React.FC = () => {
145150 return ;
146151 }
147152
148- navigate ( '/magic-link -sent' ) ;
153+ navigate ( '/magiclinks -sent' ) ;
149154 } catch ( err ) {
150155 console . error ( err ) ;
151156 setFormErrors ( 'Failed to send magic link.' ) ;
@@ -175,8 +180,9 @@ const Login: React.FC = () => {
175180 e . preventDefault ( ) ;
176181
177182 if ( mode === 'login' ) {
183+ const res = login ( identifier , passkeyAvailable ) ;
178184 if ( passkeyAvailable ) {
179- const res = login ( fetchWithAuth , identifier , passkeyAvailable ) ;
185+ console . log ( 'herro' ) ;
180186 } else {
181187 setShowFallbackOptions ( true ) ;
182188 console . log ( setShowFallbackOptions ) ;
0 commit comments