@thzero/library_client_firebase 0.14.7 → 0.14.12

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 CHANGED
@@ -1,6 +1,6 @@
1
- import firebase from 'firebase/app';
2
- import 'firebase/auth';
3
- import '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 LibraryConstants from '@thzero/library_client/constants';
6
6
 
@@ -22,9 +22,9 @@ export default ({
22
22
  const configFirebase = configExternal.firebase;
23
23
  if (!configFirebase)
24
24
  throw Error('Invalid firebase config.');
25
- firebase.initializeApp(configFirebase);
25
+ const firebaseApp = initializeApp(configFirebase);
26
26
  if (configFirebase.measurementId)
27
- firebase.analytics();
27
+ getAnalytics();
28
28
 
29
29
  let outsideResolve;
30
30
  let outsideReject;
@@ -33,7 +33,8 @@ export default ({
33
33
  outsideReject = reject;
34
34
  });
35
35
 
36
- // if (firebase.auth().currentUser) {
36
+ const firebaseAuth = getAuth();
37
+ // if (firebaseAuth.currentUser) {
37
38
  // const timer = setInterval(async () => {
38
39
  // clearInterval(timer)
39
40
  // const auth = GlobalUtility.$injector.getService(LibraryConstants.InjectorKeys.SERVICE_AUTH)
@@ -42,7 +43,7 @@ export default ({
42
43
  // }
43
44
  // eslint-disable-next-line
44
45
  let init = false;
45
- firebase.auth().onAuthStateChanged(async function(user) {
46
+ firebaseAuth.onAuthStateChanged(async function(user) {
46
47
  // if (user == null) {
47
48
  // // GlobalUtility.$navRouter.push('/auth')
48
49
  // return
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@thzero/library_client_firebase",
3
- "version": "0.14.7",
3
+ "version": "0.14.12",
4
4
  "version_major": 0,
5
5
  "version_minor": 14,
6
- "version_patch": 7,
7
- "version_date": "09/01/2021",
6
+ "version_patch": 12,
7
+ "version_date": "09/26/2021",
8
8
  "author": "thZero",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -21,11 +21,11 @@
21
21
  "test": "echo \"Error: no test specified\" && exit 1"
22
22
  },
23
23
  "dependencies": {
24
- "firebase": "^9.0.1",
24
+ "firebase": "^9.1.0",
25
25
  "@thzero/library_client": "^0.14",
26
26
  "@thzero/library_common": "^0.13"
27
27
  },
28
28
  "devDependencies": {
29
- "@thzero/library_cli": "^0.13.17"
29
+ "@thzero/library_cli": "^0.13.19"
30
30
  }
31
31
  }
package/service/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import firebase from 'firebase/app';
2
- import 'firebase/auth';
1
+ // import firebase from 'firebase/app';
2
+ // import 'firebase/auth';
3
+ import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
3
4
 
4
5
  import LibraryConstants from '@thzero/library_client/constants';
5
6
 
@@ -19,7 +20,7 @@ class FirebaseAuthService extends UserAuthService {
19
20
 
20
21
  async deleteUser(correlationId) {
21
22
  try {
22
- const user = await firebase.auth().currentUser;
23
+ const user = await getAuth().currentUser;
23
24
  if (!user)
24
25
  return;
25
26
 
@@ -39,13 +40,13 @@ class FirebaseAuthService extends UserAuthService {
39
40
  }
40
41
 
41
42
  get externalUser() {
42
- const user = firebase.auth().currentUser;
43
+ const user = getAuth().currentUser;
43
44
  this._logger.debug('FirebaseAuthService', 'tokenUser', 'user', user, LibraryUtility.generateId());
44
45
  return user;
45
46
  }
46
47
 
47
48
  get isAuthenticated() {
48
- const user = this.user;
49
+ const user = getAuth().currentUser;
49
50
  this._logger.debug('FirebaseAuthService', 'isAuthenticated', 'user', user);
50
51
  return user != null;
51
52
  }
@@ -86,8 +87,11 @@ class FirebaseAuthService extends UserAuthService {
86
87
  return false;
87
88
 
88
89
  try {
89
- const result = await firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider());
90
+ const provider = new GoogleAuthProvider();
91
+ const result = await signInWithPopup(getAuth(), provider);
90
92
  if (result && result.user) {
93
+ //const credential = GoogleAuthProvider.credentialFromResult(result);
94
+ // const token = credential.accessToken;
91
95
  this.updateExternalUser(correlationId, result.user);
92
96
  // this._serviceRouter.route('/')
93
97
  window.location.href = '/';
@@ -107,7 +111,7 @@ class FirebaseAuthService extends UserAuthService {
107
111
  async signInCompleted(correlationId) {
108
112
  // if (await auth.isAuthenticated())
109
113
  // return
110
- // firebase.auth().getRedirectResult().then(function (result) {
114
+ // getAuth().getRedirectResult().then(function (result) {
111
115
  // if (result.credential) {
112
116
  // // This gives you a Google Access Token. You can use it to access the Google API.
113
117
  // // eslint-disable-next-line
@@ -135,14 +139,14 @@ class FirebaseAuthService extends UserAuthService {
135
139
 
136
140
  async signOut(correlationId) {
137
141
  try {
138
- // await firebase.auth().signOut()
142
+ // await getAuth().signOut()
139
143
  // await this._serviceUser.dispatcher.user.setTokenResult(correlationId, null)
140
144
  // await this._serviceUser.dispatcher.user.setClaims(correlationId, null)
141
145
  // await this._serviceUser.dispatcher.user.setUser(correlationId, null)
142
146
  // await this._serviceUser.dispatcher.user.setLoggedIn(correlationId, false)
143
147
 
144
148
  const list = [];
145
- list.push(firebase.auth().signOut());
149
+ list.push(getAuth().signOut());
146
150
  // list.push(this._serviceUser.dispatcher.user.setTokenResult(correlationId, null))
147
151
  // list.push(this._serviceUser.dispatcher.user.setClaims(correlationId, null))
148
152
  // list.push(this._serviceUser.dispatcher.user.setUser(correlationId, null))
@@ -187,7 +191,7 @@ class FirebaseAuthService extends UserAuthService {
187
191
  }
188
192
 
189
193
  this._logger.debug('FirebaseAuthService', 'tokenUser', 'forceRefresh', forceRefresh, correlationId);
190
- const currentUser = await firebase.auth().currentUser;
194
+ const currentUser = await getAuth().currentUser;
191
195
  this._logger.debug('FirebaseAuthService', 'tokenUser', 'currentUser', currentUser, correlationId);
192
196
  if (!currentUser)
193
197
  return;
@@ -209,7 +213,7 @@ class FirebaseAuthService extends UserAuthService {
209
213
  const diff = expired.diff(now);
210
214
  const min = 5 * 60 * 1000;
211
215
  if (diff <= min) {
212
- await this.refreshToken(correlationId, this.user, true).then();
216
+ await this.refreshToken(correlationId, getAuth().currentUser, true).then();
213
217
  return;
214
218
  }
215
219