@edgedev/firebase 1.5.10 → 1.5.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/README.md CHANGED
@@ -32,7 +32,8 @@ const config = {
32
32
  messagingSenderId: "your-messagingSenderId",
33
33
  appId: "your-appId"
34
34
  };
35
- const edgeFirebase = new EdgeFirebase(config);
35
+ 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
+ const edgeFirebase = new EdgeFirebase(config, isPersistant);
36
37
  export { edgeFirebase };
37
38
  ```
38
39
 
@@ -50,6 +51,7 @@ import App from "./App.vue";
50
51
 
51
52
  //edgeFirebase Plugin
52
53
  import eFb from "@edgedev/firebase";
54
+ 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.
53
55
  app.use(eFb, {
54
56
  apiKey: "your-apiKey",
55
57
  authDomain: "your-authDomain",
@@ -57,7 +59,7 @@ app.use(eFb, {
57
59
  storageBucket: "your-storageBucket",
58
60
  messagingSenderId: "your-messagingSenderId",
59
61
  appId: "your-appId"
60
- })
62
+ }, isPersistant)
61
63
  //end edgeFirebase
62
64
 
63
65
  app.mount("#app");
@@ -318,14 +320,12 @@ interface permissions {
318
320
 
319
321
  (currently only sign in with email and password is supported)
320
322
 
321
- 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.
322
323
  ```javascript
323
324
  edgeFirebase.logIn(
324
325
  {
325
326
  email: "devs@edgemarketing.com",
326
327
  password: "pasword"
327
- },
328
- true // : persistence
328
+ }
329
329
  );
330
330
  ```
331
331
 
package/edgeFirebase.ts CHANGED
@@ -25,8 +25,7 @@ import {
25
25
  } from "firebase/firestore";
26
26
 
27
27
  import {
28
- getAuth,
29
- setPersistence,
28
+ initializeAuth,
30
29
  browserSessionPersistence,
31
30
  browserLocalPersistence,
32
31
  Persistence,
@@ -165,11 +164,16 @@ export const EdgeFirebase = class {
165
164
  storageBucket: "",
166
165
  messagingSenderId: "",
167
166
  appId: ""
168
- }
167
+ },
168
+ isPersistant: false
169
169
  ) {
170
170
  this.firebaseConfig = firebaseConfig;
171
171
  this.app = initializeApp(this.firebaseConfig);
172
- this.auth = getAuth(this.app);
172
+ let persistence: Persistence = browserSessionPersistence;
173
+ if (isPersistant) {
174
+ persistence = browserLocalPersistence;
175
+ }
176
+ this.auth = initializeAuth(this.app, { persistence });
173
177
  this.db = getFirestore(this.app);
174
178
  this.setOnAuthStateChanged();
175
179
  }
@@ -274,6 +278,7 @@ export const EdgeFirebase = class {
274
278
  this.user.uid = null;
275
279
  this.user.loggedIn = false;
276
280
  this.user.logInError = false;
281
+ this.user.logInErrorMessage = "";
277
282
  }
278
283
  });
279
284
  };
@@ -687,44 +692,24 @@ export const EdgeFirebase = class {
687
692
  };
688
693
 
689
694
  // Composable to login and set persistence
690
- public logIn = async (credentials: Credentials, isPersistant = false): Promise<void> => {
691
- this.user.logInErrorMessage = "Initial Click"
692
- try {
693
- this.logOut();
694
- this.user.logInErrorMessage = "After Logout"
695
- let persistence: Persistence = browserSessionPersistence;
696
- if (isPersistant) {
697
- persistence = browserLocalPersistence;
698
- }
699
- await setPersistence(this.auth, persistence);
700
-
701
- this.user.logInErrorMessage = "After Persistence"
702
-
703
- signInWithEmailAndPassword(
704
- this.auth,
705
- credentials.email,
706
- credentials.password
707
- )
708
- .then(() => {
709
- this.user.logInError = false;
710
- this.user.logInErrorMessage = "Login Sent to Firebase"
711
- })
712
- .catch((error) => {
713
- this.user.email = "";
714
- this.user.uid = null;
715
-
716
- this.user.loggedIn = false;
717
- this.user.logInError = true;
718
- this.user.logInErrorMessage = error.code + ": " + error.message;
719
- });
720
- } catch (error) {
695
+ public logIn = (credentials: Credentials): void => {
696
+ this.logOut();
697
+ signInWithEmailAndPassword(
698
+ this.auth,
699
+ credentials.email,
700
+ credentials.password
701
+ )
702
+ .then(() => {
703
+ // do nothing
704
+ })
705
+ .catch((error) => {
721
706
  this.user.email = "";
722
707
  this.user.uid = null;
723
708
 
724
709
  this.user.loggedIn = false;
725
710
  this.user.logInError = true;
726
- this.user.logInErrorMessage = JSON.stringify(error);
727
- }
711
+ this.user.logInErrorMessage = error.code + ": " + error.message;
712
+ });
728
713
  };
729
714
 
730
715
  // Keeping this for reference on how to Type a Ref.
package/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EdgeFirebase } from "./edgeFirebase";
2
2
  export default {
3
- install: (app, options) => {
4
- const eFb = new EdgeFirebase(options);
3
+ install: (app, options, isPersistant) => {
4
+ const eFb = new EdgeFirebase(options, isPersistant);
5
5
  app.provide("edgeFirebase", eFb);
6
6
  }
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.5.10",
3
+ "version": "1.5.12",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {