diff --git a/CHANGELOG.md b/CHANGELOG.md index d87a2e6c..ab83dba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [x] [#572 - Rename database-rules.json to firebase-database.json](https://github.com/scriptPilot/app-framework/issues/572) - [x] [#573 - Rename storage-rules.txt to firebase-storage.txt](https://github.com/scriptPilot/app-framework/issues/573) +- [x] [#683 - Make Firebase shortlink available in each component](https://github.com/scriptPilot/app-framework/issues/683) ([read the docs](https://github.com/scriptPilot/app-framework/blob/master/docs/firebase.md)) ## Version 1.15.0 diff --git a/client/app.js b/client/app.js index d0127ec2..9dbd3301 100644 --- a/client/app.js +++ b/client/app.js @@ -89,6 +89,25 @@ let easierLanguagePattern = { } } } +let easierFirebase = { + computed: { + // Authentication + $fireAuth() { + return window.firebase && window.firebase.auth ? window.firebase.auth : null + }, + $user() { + return this.$root.user + }, + // Realtime Database + $fireDB() { + return window.firebase && window.firebase.database ? (ref) => { return window.firebase.database().ref(ref) } : null + }, + // Cloud Storage + $fireStore() { + return window.firebase && window.firebase.storage ? (ref) => { return window.firebase.storage().ref(ref) } : null + }, + } +} let mixins = {} mixins.loadConfig = { @@ -1207,6 +1226,7 @@ function initF7VueApp () { // Use global mixins vue.mixin(easierGlobalDataObject) vue.mixin(easierLanguagePattern) + vue.mixin(easierFirebase) if (config.restoreComponentData) { vue.mixin(manageComponentData) } diff --git a/docs/firebase.md b/docs/firebase.md index d98b010f..16feae8b 100644 --- a/docs/firebase.md +++ b/docs/firebase.md @@ -24,11 +24,10 @@ Disabling a service will reduce the build size. You can use Firebase in any Vue hook `created` or later: -- `window.firebase` - Firebase application instance -- `this.$root.user` or window.user - Null or object (uid, email, name, photo) -- `this.$root.db(...)` or `window.db(...)` - Shortlink to `window.firebase.database().ref(...)` -- `this.$root.store(...)` or `window.store(...)` - Shortlink to `window.firebase.storage().ref(...)` -- `this.$root.timestamp` or `window.timestamp` - Shortlink to `window.database.ServerValue.TIMESTAMP` +- `this.$fireAuth` - Shortlink to `window.firebase.auth` +- `this.$user`- Null or object (uid, email, name, photo) +- `this.$fireDB` - Shortlink to `window.firebase.database().ref` +- `this.$fireStore` - Shortlink to `window.firebase.storage().ref` To test your Firebase rules in development, you have the chance to configure a devFirebase project: