diff --git a/src/AuthProvider.tsx b/src/AuthProvider.tsx index 32a59a0..ec2ccdc 100644 --- a/src/AuthProvider.tsx +++ b/src/AuthProvider.tsx @@ -48,7 +48,7 @@ export interface AuthContextType { credentials: Credential[]; updateCredential: (credential: Credential) => Promise; deleteCredential: (credentialId: string) => Promise; - login: (identifier: string, passkeyAvailable: boolean) => Promise; + login: (identifier: string, passkeyAvailable: boolean) => Promise; handlePasskeyLogin: () => Promise; loading: boolean; } @@ -109,13 +109,17 @@ export const AuthProvider: React.FC = ({ const login = async ( identifier: string, passkeyAvailable: boolean - ): Promise => { - const response = await fetchWithAuth(`/login`, { - method: 'POST', - body: JSON.stringify({ identifier, passkeyAvailable }), - }); - - return response; + ): Promise => { + try { + const response = await fetchWithAuth(`/login`, { + method: 'POST', + body: JSON.stringify({ identifier, passkeyAvailable }), + }); + return response; + } catch (error) { + console.error('Error fetching,', error); + return null; + } }; const handlePasskeyLogin = async () => { diff --git a/src/components/AuthFallbackOptions.tsx b/src/components/AuthFallbackOptions.tsx index 5bd4907..e56f59e 100644 --- a/src/components/AuthFallbackOptions.tsx +++ b/src/components/AuthFallbackOptions.tsx @@ -27,7 +27,7 @@ const AuthFallbackOptions: React.FC = ({ return (
-
Passkeys unavailable on this device
+
Trouble with passkey login?

Choose another secure sign-in method.

diff --git a/src/views/Login.tsx b/src/views/Login.tsx index ce2c28a..180b108 100644 --- a/src/views/Login.tsx +++ b/src/views/Login.tsx @@ -155,12 +155,14 @@ const Login: React.FC = () => { if (mode === 'login') { const loginRes = await login(identifier, passkeyAvailable); - if (loginRes.ok && passkeyAvailable) { + if (loginRes && loginRes.ok && passkeyAvailable) { const passkeyResult = await handlePasskeyLogin(); + if (passkeyResult) { navigate('/'); } } else { + setIdentifierError('An error occurred'); setShowFallbackOptions(true); } }