This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to [email protected] and [email protected].
I initially tried to go to [email protected], the current release, but it redoes the way that module imports work. It seems straightforward to update our code to use the 'compat' versions of the modules per the instructions at https://firebase.google.com/docs/web/modular-upgrade, but the third-party vuefire package doesn't seem to have been updated yet (vuejs/vuefire#1128) so we're stuck at version 8 for now. Also switch from the deprecated @firebase/testing package to @firebase/rules-unit-testing. Luckily, it seems to be a drop-in replacement.
- Loading branch information
Showing
9 changed files
with
7,933 additions
and
5,087 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
import { Component, Mixins } from 'vue-property-decorator'; | ||
import { logError, logInfo } from '@/log'; | ||
import { getAuth, getFirebase, getFirebaseUI, getFirestore } from '@/firebase'; | ||
import { getAuth, getFirebaseUI, getFirestore } from '@/firebase'; | ||
import Perf from '@/mixins/Perf'; | ||
|
@@ -46,84 +46,92 @@ export default class Login extends Mixins(Perf) { | |
completingLogin = false; | ||
mounted() { | ||
Promise.all([getAuth(), getFirebase(), getFirebaseUI()]).then( | ||
([auth, firebase, firebaseui]) => { | ||
// See https://github.com/firebase/firebaseui-web/issues/293. | ||
let ui = firebaseui.auth.AuthUI.getInstance(); | ||
if (!ui) ui = new firebaseui.auth.AuthUI(auth); | ||
Promise.all([getAuth(), getFirebaseUI()]).then(([auth, firebaseui]) => { | ||
// See https://github.com/firebase/firebaseui-web/issues/293. | ||
let ui = firebaseui.auth.AuthUI.getInstance(); | ||
if (!ui) ui = new firebaseui.auth.AuthUI(auth); | ||
this.pendingRedirect = ui.isPendingRedirect(); | ||
if (!this.pendingRedirect) this.logReady('login_loaded'); | ||
this.pendingRedirect = ui.isPendingRedirect(); | ||
if (!this.pendingRedirect) this.logReady('login_loaded'); | ||
// As far as I can tell, there's no way to localize FirebaseUI's auth | ||
// interface without loading a completely different version of the | ||
// library from the CDN: | ||
// | ||
// https://github.com/firebase/firebaseui-web#localized-widget | ||
// https://github.com/firebase/firebaseui-web/issues/9 | ||
// https://github.com/firebase/firebaseui-web/issues/242 | ||
// | ||
// Best comment on that last bug: | ||
// | ||
// > > Each internationalized version is a separate build. Including all | ||
// > > the versions in one file is not feasible. | ||
// | ||
// > Oh dear. Looks like you've used the wrong implementation architecture | ||
// > to support i18n for SPA web apps! | ||
// | ||
// There *is* a |languageCode| field on firebase.auth.Auth, but I'm not | ||
// sure what it does: | ||
// https://firebase.google.com/docs/reference/js/firebase.auth.Auth.html#languagecode | ||
ui.start('#firebaseui-auth-container', { | ||
// Disable the account chooser, which is ugly and doesn't seem to work | ||
// correctly with this logic (i.e. after signing out and trying to | ||
// sign in with email, I just see a spinner): | ||
// https://stackoverflow.com/q/37369929 | ||
credentialHelper: firebaseui.auth.CredentialHelper.NONE, | ||
signInOptions: [ | ||
firebase.auth.GoogleAuthProvider.PROVIDER_ID, | ||
firebase.auth.EmailAuthProvider.PROVIDER_ID, | ||
], | ||
callbacks: { | ||
signInSuccessWithAuthResult: () => { | ||
this.completingLogin = true; | ||
// As far as I can tell, there's no way to localize FirebaseUI's auth | ||
// interface without loading a completely different version of the | ||
// library from the CDN: | ||
// | ||
// https://github.com/firebase/firebaseui-web#localized-widget | ||
// https://github.com/firebase/firebaseui-web/issues/9 | ||
// https://github.com/firebase/firebaseui-web/issues/242 | ||
// | ||
// Best comment on that last bug: | ||
// | ||
// > > Each internationalized version is a separate build. Including all | ||
// > > the versions in one file is not feasible. | ||
// | ||
// > Oh dear. Looks like you've used the wrong implementation architecture | ||
// > to support i18n for SPA web apps! | ||
// | ||
// There *is* a |languageCode| field on firebase.auth.Auth, but I'm not | ||
// sure what it does: | ||
// https://firebase.google.com/docs/reference/js/firebase.auth.Auth.html#languagecode | ||
ui.start('#firebaseui-auth-container', { | ||
// Disable the account chooser, which is ugly and doesn't seem to work | ||
// correctly with this logic (i.e. after signing out and trying to | ||
// sign in with email, I just see a spinner): | ||
// https://stackoverflow.com/q/37369929 | ||
credentialHelper: firebaseui.auth.CredentialHelper.NONE, | ||
signInOptions: [ | ||
// These correspond to the static variables | ||
// firebase.auth.GoogleAuthProvider.PROVIDER_ID and | ||
// firebase.auth.EmailAuthProvider.PROVIDER_ID (and I think also the | ||
// ProviderId enum at | ||
// https://firebase.google.com/docs/reference/js/auth.md#providerid). | ||
// I can't figure out how to access any of these in [email protected] | ||
// using the dynamic imports in @/firebase/index.ts. Worryingly, these | ||
// seemed to formerly be 'google' and 'email', but if you use invalid | ||
// strings you appear to get unclickable login buttons in the UI, so | ||
// it seems easy to notice. | ||
'google.com', | ||
'password', | ||
], | ||
callbacks: { | ||
signInSuccessWithAuthResult: () => { | ||
this.completingLogin = true; | ||
Promise.all([getAuth(), getFirestore()]).then(([auth, db]) => { | ||
const user = auth.currentUser; | ||
if (!user) throw new Error('Not logged in'); | ||
const ref = db.collection('users').doc(user.uid); | ||
ref.get().then((snap) => { | ||
if (snap.exists) { | ||
// If the user has logged in before, send them to the routes | ||
// view. | ||
this.$router.replace('routes'); | ||
} else { | ||
// Otherwise, create the doc using their display name and | ||
// send them to the profile view. Note that the name is null | ||
// when using the email provider. | ||
const name = user.displayName || 'Unknown Climber'; | ||
logInfo('create_user', { name }); | ||
ref | ||
.set({ name }, { merge: true }) | ||
.then(() => { | ||
this.$router.replace('profile'); | ||
}) | ||
.catch((err) => { | ||
this.$emit('error-msg', `Failed creating user: ${err}`); | ||
logError('create_user_failed', err); | ||
}); | ||
} | ||
}); | ||
Promise.all([getAuth(), getFirestore()]).then(([auth, db]) => { | ||
const user = auth.currentUser; | ||
if (!user) throw new Error('Not logged in'); | ||
const ref = db.collection('users').doc(user.uid); | ||
ref.get().then((snap) => { | ||
if (snap.exists) { | ||
// If the user has logged in before, send them to the routes | ||
// view. | ||
this.$router.replace('routes'); | ||
} else { | ||
// Otherwise, create the doc using their display name and | ||
// send them to the profile view. Note that the name is null | ||
// when using the email provider. | ||
const name = user.displayName || 'Unknown Climber'; | ||
logInfo('create_user', { name }); | ||
ref | ||
.set({ name }, { merge: true }) | ||
.then(() => { | ||
this.$router.replace('profile'); | ||
}) | ||
.catch((err) => { | ||
this.$emit('error-msg', `Failed creating user: ${err}`); | ||
logError('create_user_failed', err); | ||
}); | ||
} | ||
}); | ||
}); | ||
// Don't redirect automatically; we handle that above. | ||
return false; | ||
}, | ||
uiShown: () => this.recordEvent('loginShown'), | ||
// Don't redirect automatically; we handle that above. | ||
return false; | ||
}, | ||
}); | ||
} | ||
); | ||
uiShown: () => this.recordEvent('loginShown'), | ||
}, | ||
}); | ||
}); | ||
} | ||
} | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters