Skip to content

Commit

Permalink
fix: web authn is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
czabaj committed Dec 19, 2024
1 parent d8faccf commit abf1260
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/backend/Firebase.res
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,15 @@ module StyledFirebaseAuth = {
module Functions = {
type t

// we are currently using just these two, but more can be added if needed
// @see https://firebase.google.com/docs/functions/locations
type functionLocation = [#"europe-central2" | #"europe-west3"]

@module("firebase/functions")
external getFunctions: FirebaseApp.t => t = "getFunctions"

@module("firebase/functions")
external getFunctionsInRegion: (FirebaseApp.t, string) => t = "getFunctions"
external getFunctionsInRegion: (FirebaseApp.t, functionLocation) => t = "getFunctions"

type callResult<'a> = {data: 'a}
@module("firebase/functions")
Expand Down
9 changes: 5 additions & 4 deletions src/backend/FirebaseWebAuthn.res
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
@module("@firebase-web-authn/browser")
external linkWithPasskey: (
external createUserWithPasskey: (
Firebase.Auth.t,
Firebase.Functions.t,
string,
) => promise<Firebase.Auth.userCredential> = "linkWithPasskey"
) => promise<Firebase.Auth.userCredential> = "createUserWithPasskey"

@module("@firebase-web-authn/browser")
external createUserWithPasskey: (
external linkWithPasskey: (
Firebase.Auth.t,
Firebase.Functions.t,
string,
) => promise<Firebase.Auth.userCredential> = "createUserWithPasskey"
) => promise<Firebase.Auth.userCredential> = "linkWithPasskey"


@module("@firebase-web-authn/browser")
external signInWithPasskey: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let make = (~children) => {
Auth.setLanguageCode(auth, "cs")

let analytics = app->Analytics.getAnalytics
let functions = app->Functions.getFunctionsInRegion(`europe-west3`)
let functions = app->Functions.getFunctionsInRegion(#"europe-west3")
let messaging = app->Messaging.getMessaging

<AppCheckProvider sdk=appCheck>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Onboarding/Onboarding.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let make = (~children, ~user: Firebase.User.t) => {
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 functions = app->Firebase.Functions.getFunctionsInRegion(#"europe-central2")
let _ = await FirebaseWebAuthn.linkWithPasskey(auth, functions, email)
setWebAuthn(Some("1"))
} catch {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Unauthenticated/Unauthenticated.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let make = () => {
let (view, setView) = React.useState(() => SignIn)
let (signInWithPasskey, runSignInWithPasskey) = Hooks.usePromise(() => {
// TODO: upgrade the FirebaseWebAuthn and deploy to "europe-west3"
let functions = app->Firebase.Functions.getFunctionsInRegion(`us-central1`)
let functions = app->Firebase.Functions.getFunctionsInRegion(#"europe-central2")
FirebaseWebAuthn.signInWithPasskey(auth, functions)
})
let isOnlineStatus = DomUtils.useIsOnline()
Expand Down

0 comments on commit abf1260

Please sign in to comment.