@thzero/library_client_firebase 0.17.7 → 0.17.8
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/boot/starter.js +42 -40
- package/package.json +3 -3
- package/service/index.js +51 -12
package/boot/starter.js
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
import { initializeApp } from 'firebase/app';
|
|
2
|
-
import { getAuth } from "firebase/auth";
|
|
3
|
-
import { getAnalytics } from "firebase/analytics";
|
|
1
|
+
// import { initializeApp } from 'firebase/app';
|
|
2
|
+
// import { getAuth } from "firebase/auth";
|
|
3
|
+
// import { getAnalytics } from "firebase/analytics";
|
|
4
4
|
|
|
5
5
|
import LibraryClientConstants from '@thzero/library_client/constants';
|
|
6
6
|
|
|
7
7
|
import LibrartyClientUtility from '@thzero/library_client/utility/index';
|
|
8
8
|
|
|
9
|
-
import config from 'local-config';
|
|
9
|
+
// import config from 'local-config';
|
|
10
10
|
|
|
11
11
|
// export default async ({
|
|
12
|
-
export default (
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
12
|
+
export default (router) => {
|
|
13
|
+
const auth = LibrartyClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_AUTH);
|
|
14
|
+
return auth.initialize(router);
|
|
15
|
+
// const configExternal = config.external;
|
|
16
|
+
// if (!configExternal)
|
|
17
|
+
// throw Error('Invalid external config.');
|
|
18
|
+
// const configFirebase = configExternal.firebase;
|
|
19
|
+
// if (!configFirebase)
|
|
20
|
+
// throw Error('Invalid firebase config.');
|
|
21
|
+
// initializeApp(configFirebase);
|
|
22
|
+
// if (configFirebase.measurementId)
|
|
23
|
+
// getAnalytics();
|
|
24
|
+
|
|
25
|
+
// let outsideResolve;
|
|
26
|
+
// let outsideReject;
|
|
27
|
+
// const promiseAuth = new Promise(function(resolve, reject) {
|
|
28
|
+
// outsideResolve = resolve;
|
|
29
|
+
// outsideReject = reject;
|
|
30
|
+
// });
|
|
31
|
+
|
|
32
|
+
// const firebaseAuth = getAuth();
|
|
33
|
+
// // eslint-disable-next-line
|
|
34
|
+
// let init = false;
|
|
35
|
+
// firebaseAuth.onAuthStateChanged(async function(user) {
|
|
36
|
+
// const auth = LibrartyClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_AUTH);
|
|
37
|
+
// await auth.onAuthStateChanged(user);
|
|
38
|
+
// if (!init) {
|
|
39
|
+
// init = true;
|
|
40
|
+
// outsideResolve(true);
|
|
41
|
+
// return;
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// outsideReject();
|
|
45
|
+
// });
|
|
46
|
+
|
|
47
|
+
// setup();
|
|
48
|
+
|
|
49
|
+
// return promiseAuth;
|
|
48
50
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/library_client_firebase",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.8",
|
|
4
4
|
"version_major": 0,
|
|
5
5
|
"version_minor": 17,
|
|
6
|
-
"version_patch":
|
|
7
|
-
"version_date": "04/
|
|
6
|
+
"version_patch": 8,
|
|
7
|
+
"version_date": "04/20/2023",
|
|
8
8
|
"author": "thZero",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
package/service/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
// import
|
|
1
|
+
import { initializeApp } from 'firebase/app';
|
|
2
|
+
// import { getAuth } from "firebase/auth";
|
|
3
|
+
import { getAnalytics } from "firebase/analytics";
|
|
3
4
|
import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
|
|
4
5
|
|
|
5
6
|
import LibraryClientConstants from '@thzero/library_client/constants';
|
|
@@ -18,6 +19,12 @@ class FirebaseAuthService extends UserAuthService {
|
|
|
18
19
|
this._serviceRouter = null;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
async init(injector) {
|
|
23
|
+
await super.init(injector);
|
|
24
|
+
|
|
25
|
+
this._serviceRouter = this._injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ROUTER);
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
async deleteUser(correlationId) {
|
|
22
29
|
try {
|
|
23
30
|
const user = await getAuth().currentUser;
|
|
@@ -33,28 +40,56 @@ class FirebaseAuthService extends UserAuthService {
|
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
async init(injector) {
|
|
37
|
-
await super.init(injector);
|
|
38
|
-
|
|
39
|
-
this._serviceRouter = this._injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ROUTER);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
43
|
get externalUser() {
|
|
43
44
|
const user = getAuth().currentUser;
|
|
44
45
|
this._logger.debug('FirebaseAuthService', 'tokenUser', 'user', user, LibraryCommonUtility.generateId());
|
|
45
46
|
return user;
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
async initialize(router) {
|
|
50
|
+
const configExternal = this._config.getExternal();
|
|
51
|
+
if (!configExternal)
|
|
52
|
+
throw Error('Invalid external config.');
|
|
53
|
+
const configFirebase = configExternal.firebase;
|
|
54
|
+
if (!configFirebase)
|
|
55
|
+
throw Error('Invalid firebase config.');
|
|
56
|
+
initializeApp(configFirebase);
|
|
57
|
+
if (configFirebase.measurementId)
|
|
58
|
+
getAnalytics();
|
|
59
|
+
|
|
60
|
+
let outsideResolve;
|
|
61
|
+
let outsideReject;
|
|
62
|
+
const promiseAuth = new Promise(function(resolve, reject) {
|
|
63
|
+
outsideResolve = resolve;
|
|
64
|
+
outsideReject = reject;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const self = this;
|
|
68
|
+
const firebaseAuth = getAuth();
|
|
69
|
+
// eslint-disable-next-line
|
|
70
|
+
let init = false;
|
|
71
|
+
firebaseAuth.onAuthStateChanged(async function(user) {
|
|
72
|
+
// const auth = LibrartyClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_AUTH);
|
|
73
|
+
// await auth.onAuthStateChanged(user);
|
|
74
|
+
await self.onAuthStateChanged(user);
|
|
75
|
+
if (!init) {
|
|
76
|
+
init = true;
|
|
77
|
+
outsideResolve(true);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
outsideReject();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return promiseAuth;
|
|
85
|
+
}
|
|
86
|
+
|
|
48
87
|
get isAuthenticated() {
|
|
49
88
|
const user = getAuth().currentUser;
|
|
50
89
|
this._logger.debug('FirebaseAuthService', 'isAuthenticated', 'user', user);
|
|
51
90
|
return user !== null;
|
|
52
91
|
}
|
|
53
92
|
|
|
54
|
-
get token() {
|
|
55
|
-
return this._serviceUser.token;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
93
|
async onAuthStateChanged(user) {
|
|
59
94
|
const correlationId = LibraryCommonUtility.correlationId();
|
|
60
95
|
try {
|
|
@@ -317,6 +352,10 @@ class FirebaseAuthService extends UserAuthService {
|
|
|
317
352
|
});
|
|
318
353
|
}
|
|
319
354
|
|
|
355
|
+
get token() {
|
|
356
|
+
return this._serviceUser.token;
|
|
357
|
+
}
|
|
358
|
+
|
|
320
359
|
// async token(forceRefresh) {
|
|
321
360
|
// if (!forceRefresh)
|
|
322
361
|
// forceRefresh = false
|