Skip to content

Commit

Permalink
fix: unable to sign-in with biometrics
Browse files Browse the repository at this point in the history
  • Loading branch information
czabaj committed Nov 12, 2024
1 parent 4195460 commit 1968eb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/pages/Onboarding/Onboarding.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ type view = NickName | ThrustDevice | BiometricAuthn

@react.component
let make = (~children, ~user: Firebase.User.t) => {
let app = Reactfire.useFirebaseApp()
let auth = Reactfire.useAuth()
let functions = Reactfire.useFunctions()
let supportsWebAuthn = DomUtils.useSuportsPlatformWebauthn()
let (webAuthn, setWebAuthn) = AppStorage.useLocalStorage(AppStorage.keyWebAuthn)
let (thrustDevice, setThrustDevice) = AppStorage.useLocalStorage(AppStorage.keyThrustDevice)
Expand All @@ -21,6 +21,8 @@ let make = (~children, ~user: Firebase.User.t) => {
let (setupWebAuthn, runSetupWebAuthn) = Hooks.usePromise(async () => {
let email = user.email->Null.getExn
try {
// TODO: upgrade the FirebaseWebAuthn and deploy to "europe-west3"
let functions = app->Firebase.Functions.getFunctionsInRegion(`us-central1`)
let _ = await FirebaseWebAuthn.linkWithPasskey(auth, functions, email)
setWebAuthn(Some("1"))
} catch {
Expand Down
18 changes: 10 additions & 8 deletions src/pages/Unauthenticated/Unauthenticated.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ type views = ForgotPassword(string) | ForgotPasswordSent(string) | SignIn | Sign
@react.component
let make = () => {
open Firebase.Auth
let app = Reactfire.useFirebaseApp()
let auth = Reactfire.useAuth()
let functions = Reactfire.useFunctions()
let (view, setView) = React.useState(() => SignIn)
let (signInWithPasskey, runSignInWithPasskey) = Hooks.usePromise(() =>
FirebaseWebAuthn.signInWithPasskey(. auth, functions)
)
let (signInWithPasskey, runSignInWithPasskey) = Hooks.usePromise(() => {
// TODO: upgrade the FirebaseWebAuthn and deploy to "europe-west3"
let functions = app->Firebase.Functions.getFunctionsInRegion(`us-central1`)
FirebaseWebAuthn.signInWithPasskey(auth, functions)
})
let isOnlineStatus = DomUtils.useIsOnline()
let isOnline = isOnlineStatus.data
let supportsWebAuthn = DomUtils.useSuportsPlatformWebauthn()
Expand All @@ -32,7 +34,7 @@ let make = () => {
initialEmail
onGoBack={() => setView(_ => SignIn)}
onSubmit={values => {
sendPasswordResetEmail(. auth, ~email=values.email)->Promise.then(_ => {
sendPasswordResetEmail(auth, ~email=values.email)->Promise.then(_ => {
setView(_ => ForgotPasswordSent(values.email))
Promise.resolve()
})
Expand All @@ -46,7 +48,7 @@ let make = () => {
loadingOverlay={signInWithPasskey.state === #pending}
onForgottenPassword={email => setView(_ => ForgotPassword(email))}
onSignInWithGoogle={() => {
signInWithRedirect(. auth, FederatedAuthProvider.googleAuthProvider())
signInWithRedirect(auth, FederatedAuthProvider.googleAuthProvider())
->Promise.catch(error => {
let exn = Js.Exn.asJsExn(error)->Option.getExn
LogUtils.captureException(exn)
Expand All @@ -56,7 +58,7 @@ let make = () => {
}}
onSignInWithPasskey={!webAuthnReady ? None : Some(runSignInWithPasskey)}
onSignInWithPassword={({email, password}) => {
signInWithEmailAndPassword(. auth, ~email, ~password)->Promise.thenResolve(_ => ())
signInWithEmailAndPassword(auth, ~email, ~password)->Promise.thenResolve(_ => ())
}}
onSignUp={() => setView(_ => SignUp)}
/>
Expand All @@ -65,7 +67,7 @@ let make = () => {
isOnline
onGoBack={() => setView(_ => SignIn)}
onSubmit={({email, password}) => {
createUserWithEmailAndPassword(. auth, ~email, ~password)->Promise.thenResolve(_ => ())
createUserWithEmailAndPassword(auth, ~email, ~password)->Promise.thenResolve(_ => ())
}}
/>
}
Expand Down

0 comments on commit 1968eb7

Please sign in to comment.