|
1 | | -import { MaterialIcons } from "@expo/vector-icons"; |
| 1 | +import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"; |
2 | 2 | import { authClient, oauthProviders } from "@openmapx/core"; |
3 | 3 | import { useCallback, useState } from "react"; |
4 | 4 | import { useTranslation } from "react-i18next"; |
@@ -184,6 +184,25 @@ export function AuthDialog({ visible, onDismiss }: AuthDialogProps) { |
184 | 184 | } |
185 | 185 | }, [email, resetOtp, newPassword, resetForm, t]); |
186 | 186 |
|
| 187 | + const handlePasskeySignIn = useCallback(async () => { |
| 188 | + Keyboard.dismiss(); |
| 189 | + setLoading(true); |
| 190 | + setError(null); |
| 191 | + try { |
| 192 | + const { error: passkeyError } = await authClient.signIn.passkey(); |
| 193 | + if (passkeyError) { |
| 194 | + if ("code" in passkeyError && passkeyError.code === "AUTH_CANCELLED") return; |
| 195 | + setError(String(passkeyError.message ?? t("auth.passkeySignInFailed"))); |
| 196 | + return; |
| 197 | + } |
| 198 | + handleClose(); |
| 199 | + } catch { |
| 200 | + setError(t("auth.passkeyAuthFailed")); |
| 201 | + } finally { |
| 202 | + setLoading(false); |
| 203 | + } |
| 204 | + }, [handleClose, t]); |
| 205 | + |
187 | 206 | const handleOAuthSignIn = useCallback( |
188 | 207 | async (providerId: string, providerName: string) => { |
189 | 208 | setLoading(true); |
@@ -456,6 +475,22 @@ export function AuthDialog({ visible, onDismiss }: AuthDialogProps) { |
456 | 475 |
|
457 | 476 | <Divider style={styles.divider} /> |
458 | 477 |
|
| 478 | + {/* Passkey sign-in */} |
| 479 | + {mode === "sign-in" && ( |
| 480 | + <Button |
| 481 | + mode="outlined" |
| 482 | + onPress={handlePasskeySignIn} |
| 483 | + disabled={loading} |
| 484 | + icon={({ size, color }) => ( |
| 485 | + <MaterialCommunityIcons name="key-variant" size={size} color={color} /> |
| 486 | + )} |
| 487 | + style={styles.oauthButton} |
| 488 | + labelStyle={{ color: theme.colors.onSurface }} |
| 489 | + > |
| 490 | + {t("auth.signInWithPasskey")} |
| 491 | + </Button> |
| 492 | + )} |
| 493 | + |
459 | 494 | {/* OAuth providers */} |
460 | 495 | {oauthProviders.map((provider) => ( |
461 | 496 | <Button |
|
0 commit comments