@edgedev/firebase 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/edgeFirebase.ts +20 -72
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,9 @@ const config = {
|
|
|
30
30
|
projectId: "your-projectId",
|
|
31
31
|
storageBucket: "your-storageBucket",
|
|
32
32
|
messagingSenderId: "your-messagingSenderId",
|
|
33
|
-
appId: "your-appId"
|
|
33
|
+
appId: "your-appId",
|
|
34
|
+
emulatorAuth: "", // local emlulator port populated app will be started with auth emulator
|
|
35
|
+
emulatorFirestore: "", // local emlulator port populated app will be started with firestore emulator
|
|
34
36
|
};
|
|
35
37
|
const isPersistant = true // If "persistence" is true, login will be saved locally, they can close their browser and when they open they will be logged in automatically. If "persistence" is false login saved only for the session.
|
|
36
38
|
const edgeFirebase = new EdgeFirebase(config, isPersistant);
|
|
@@ -58,7 +60,9 @@ app.use(eFb, {
|
|
|
58
60
|
projectId: "your-projectId",
|
|
59
61
|
storageBucket: "your-storageBucket",
|
|
60
62
|
messagingSenderId: "your-messagingSenderId",
|
|
61
|
-
appId: "your-appId"
|
|
63
|
+
appId: "your-appId",
|
|
64
|
+
emulatorAuth: "", // local emlulator port populated app will be started with auth emulator
|
|
65
|
+
emulatorFirestore: "", // local emlulator port populated app will be started with firestore emulator
|
|
62
66
|
}, isPersistant)
|
|
63
67
|
//end edgeFirebase
|
|
64
68
|
|
|
@@ -79,7 +83,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
79
83
|
projectId: "your-projectId",
|
|
80
84
|
storageBucket: "your-storageBucket",
|
|
81
85
|
messagingSenderId: "your-messagingSenderId",
|
|
82
|
-
appId: "your-appId"
|
|
86
|
+
appId: "your-appId",
|
|
87
|
+
emulatorAuth: "", // local emlulator port populated app will be started with auth emulator
|
|
88
|
+
emulatorFirestore: "", // local emlulator port populated app will be started with firestore emulator
|
|
83
89
|
}, isPersistant);
|
|
84
90
|
});
|
|
85
91
|
```
|
package/edgeFirebase.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
deleteField,
|
|
25
25
|
arrayRemove,
|
|
26
26
|
arrayUnion,
|
|
27
|
+
connectFirestoreEmulator,
|
|
27
28
|
} from "firebase/firestore";
|
|
28
29
|
|
|
29
30
|
import {
|
|
@@ -39,7 +40,8 @@ import {
|
|
|
39
40
|
reauthenticateWithCredential,
|
|
40
41
|
EmailAuthProvider,
|
|
41
42
|
sendPasswordResetEmail,
|
|
42
|
-
confirmPasswordReset
|
|
43
|
+
confirmPasswordReset,
|
|
44
|
+
connectAuthEmulator,
|
|
43
45
|
} from "firebase/auth";
|
|
44
46
|
|
|
45
47
|
interface FirestoreQuery {
|
|
@@ -102,19 +104,7 @@ interface newUser {
|
|
|
102
104
|
meta: object;
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
interface user {
|
|
106
|
-
email: string;
|
|
107
|
-
roles: role[];
|
|
108
|
-
specialPermissions: specialPermission[];
|
|
109
|
-
userId: string;
|
|
110
|
-
docId: string;
|
|
111
|
-
uid: string;
|
|
112
|
-
last_updated: Date;
|
|
113
|
-
}
|
|
114
107
|
|
|
115
|
-
interface usersByEmail {
|
|
116
|
-
[email: string]: [user];
|
|
117
|
-
}
|
|
118
108
|
interface userMeta extends newUser {
|
|
119
109
|
docId: string;
|
|
120
110
|
userId: string;
|
|
@@ -143,6 +133,8 @@ interface firebaseConfig {
|
|
|
143
133
|
storageBucket: string;
|
|
144
134
|
messagingSenderId: string;
|
|
145
135
|
appId: string;
|
|
136
|
+
emulatorAuth?: string;
|
|
137
|
+
emulatorFirestore?: string;
|
|
146
138
|
}
|
|
147
139
|
|
|
148
140
|
interface actionResponse {
|
|
@@ -164,7 +156,9 @@ export const EdgeFirebase = class {
|
|
|
164
156
|
projectId: "",
|
|
165
157
|
storageBucket: "",
|
|
166
158
|
messagingSenderId: "",
|
|
167
|
-
appId: ""
|
|
159
|
+
appId: "",
|
|
160
|
+
emulatorAuth: "",
|
|
161
|
+
emulatorFirestore: ""
|
|
168
162
|
},
|
|
169
163
|
isPersistant: false
|
|
170
164
|
) {
|
|
@@ -174,8 +168,17 @@ export const EdgeFirebase = class {
|
|
|
174
168
|
if (isPersistant) {
|
|
175
169
|
persistence = browserLocalPersistence;
|
|
176
170
|
}
|
|
171
|
+
|
|
177
172
|
this.auth = initializeAuth(this.app, { persistence });
|
|
173
|
+
if (this.firebaseConfig.emulatorAuth) {
|
|
174
|
+
connectAuthEmulator(this.auth, `http://localhost:${this.firebaseConfig.emulatorAuth}`)
|
|
175
|
+
}
|
|
176
|
+
|
|
178
177
|
this.db = getFirestore(this.app);
|
|
178
|
+
if (this.firebaseConfig.emulatorFirestore) {
|
|
179
|
+
connectFirestoreEmulator(this.db, "localhost", this.firebaseConfig.emulatorFirestore)
|
|
180
|
+
}
|
|
181
|
+
|
|
179
182
|
this.setOnAuthStateChanged();
|
|
180
183
|
}
|
|
181
184
|
|
|
@@ -318,6 +321,8 @@ export const EdgeFirebase = class {
|
|
|
318
321
|
this.unsubscibe['collection-data'] = unsubscribe
|
|
319
322
|
}
|
|
320
323
|
|
|
324
|
+
|
|
325
|
+
|
|
321
326
|
private startUserMetaSync = async (): Promise<void> => {
|
|
322
327
|
await this.startCollectionPermissionsSync()
|
|
323
328
|
await this.initUserMetaPermissions();
|
|
@@ -740,64 +745,9 @@ export const EdgeFirebase = class {
|
|
|
740
745
|
|
|
741
746
|
// Simple Store Items (add matching key per firebase collection)
|
|
742
747
|
public data: CollectionDataObject = reactive({});
|
|
743
|
-
private usersByCollections: CollectionDataObject = reactive({});
|
|
744
|
-
|
|
745
|
-
public users = computed(() => {
|
|
746
|
-
const userList = {};
|
|
747
|
-
const keys = Object.keys(JSON.parse(JSON.stringify(this.usersByCollections)));
|
|
748
|
-
keys.forEach(key => {
|
|
749
|
-
const users = this.usersByCollections[key];
|
|
750
|
-
if (key.startsWith("ROLES|")) {
|
|
751
|
-
const collectionPathCheck = key.replace("ROLES|", "")
|
|
752
|
-
const userKeys = Object.keys(users);
|
|
753
|
-
if (Object.keys(users).length > 0) {
|
|
754
|
-
userKeys.forEach(userKey => {
|
|
755
|
-
const user = users[userKey];
|
|
756
|
-
if (!Object.prototype.hasOwnProperty.call(userList, user.docId)) {
|
|
757
|
-
userList[user.email] = {
|
|
758
|
-
docId: user.docId,
|
|
759
|
-
email: user.email,
|
|
760
|
-
roles: [{collectionPath: collectionPathCheck, role: user.roles[collectionPathCheck].role }],
|
|
761
|
-
specialPermissions: [],
|
|
762
|
-
meta: user.meta,
|
|
763
|
-
last_updated: user.last_updated,
|
|
764
|
-
userId: user.userId,
|
|
765
|
-
uid: user.uid
|
|
766
|
-
}
|
|
767
|
-
} else {
|
|
768
|
-
userList[user.email].roles.push({ collectionPath: collectionPathCheck, role: user.roles[collectionPathCheck].role })
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
if (key.startsWith("SPECIALPERMISSIONS|")) {
|
|
774
|
-
const collectionPathCheck = key.replace("SPECIALPERMISSIONS|", "")
|
|
775
|
-
const userKeys = Object.keys(users);
|
|
776
|
-
if (Object.keys(users).length > 0) {
|
|
777
|
-
userKeys.forEach(userKey => {
|
|
778
|
-
const user = users[userKey];
|
|
779
|
-
if (!Object.prototype.hasOwnProperty.call(userList, user.docId)) {
|
|
780
|
-
userList[user.email] = {
|
|
781
|
-
docId: user.docId,
|
|
782
|
-
email: user.email,
|
|
783
|
-
roles: [],
|
|
784
|
-
specialPermissions: [{ collectionPath: collectionPathCheck, permissions: user.specialPermissions[collectionPathCheck].permissions }],
|
|
785
|
-
meta: user.meta,
|
|
786
|
-
last_updated: user.last_updated,
|
|
787
|
-
userId: user.userId,
|
|
788
|
-
uid: user.uid
|
|
789
|
-
}
|
|
790
|
-
} else {
|
|
791
|
-
userList[user.email].specialPermissions.push({ collectionPath: collectionPathCheck, permissions: user.specialPermissions[collectionPathCheck].permissions })
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
return userList;
|
|
798
|
-
});
|
|
799
748
|
|
|
800
749
|
public unsubscibe: CollectionUnsubscribeObject = reactive({});
|
|
750
|
+
|
|
801
751
|
public user: UserDataObject = reactive({
|
|
802
752
|
uid: null,
|
|
803
753
|
email: "",
|
|
@@ -1084,8 +1034,6 @@ export const EdgeFirebase = class {
|
|
|
1084
1034
|
|
|
1085
1035
|
public startUsersSnapshot = (collectionPath = ''): void => {
|
|
1086
1036
|
this.stopSnapshot('users')
|
|
1087
|
-
// TODO: need to build users object appropriately and only show roles
|
|
1088
|
-
// and special permmisions for collectionPaths the user has assign access for
|
|
1089
1037
|
this.state.users = {};
|
|
1090
1038
|
if (collectionPath) {
|
|
1091
1039
|
if (this.permissionCheck('assign', collectionPath)) {
|