svelte-firekit 0.0.19 → 0.0.21

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.
@@ -4,7 +4,6 @@ declare class FirekitAuth {
4
4
  private firestore;
5
5
  private constructor();
6
6
  static getInstance(): FirekitAuth;
7
- getDeviceIdentifier(): string;
8
7
  signInWithGoogle(): Promise<void>;
9
8
  signInWithEmail(email: string, password: string): Promise<void>;
10
9
  registerWithEmail(email: string, password: string, displayName: string): Promise<void>;
@@ -30,7 +29,6 @@ declare class FirekitAuth {
30
29
  success: boolean;
31
30
  message: string;
32
31
  }>;
33
- updateUserSession(user: any): Promise<void>;
34
32
  }
35
33
  export declare const firekitAuth: FirekitAuth;
36
34
  export {};
package/dist/auth/auth.js CHANGED
@@ -14,19 +14,14 @@ class FirekitAuth {
14
14
  }
15
15
  return FirekitAuth.instance;
16
16
  }
17
- getDeviceIdentifier() {
18
- return navigator.userAgent; // Puedes personalizar esto según tu preferencia.
19
- }
20
17
  async signInWithGoogle() {
21
18
  const provider = new GoogleAuthProvider();
22
19
  const result = await signInWithPopup(this.auth, provider);
23
20
  await this.updateUserInFirestore(result.user);
24
- await this.updateUserSession(result.user);
25
21
  }
26
22
  async signInWithEmail(email, password) {
27
23
  const result = await signInWithEmailAndPassword(this.auth, email, password);
28
24
  await this.updateUserInFirestore(result.user);
29
- await this.updateUserSession(result.user);
30
25
  }
31
26
  async registerWithEmail(email, password, displayName) {
32
27
  const result = await createUserWithEmailAndPassword(this.auth, email, password);
@@ -34,7 +29,6 @@ class FirekitAuth {
34
29
  if (user) {
35
30
  await updateProfile(user, { displayName });
36
31
  await this.updateUserInFirestore(user);
37
- await this.updateUserSession(user);
38
32
  await sendEmailVerification(user);
39
33
  }
40
34
  }
@@ -110,30 +104,5 @@ class FirekitAuth {
110
104
  throw new Error(error.message);
111
105
  }
112
106
  }
113
- async updateUserSession(user) {
114
- let nav = this.getDeviceIdentifier().replace(/[ /]/g, '');
115
- const sessionId = `${user.uid}_${nav}`;
116
- const db = firebaseService.getDatabaseInstance();
117
- const userSessionsRef = ref(db, `sessions/${user.uid}`);
118
- const userSessionsSnap = await get(userSessionsRef);
119
- let sessionDatas = [];
120
- if (userSessionsSnap.exists()) {
121
- sessionDatas = userSessionsSnap.val().sessionDatas || [];
122
- if (sessionDatas.some(session => session.uid === sessionId)) {
123
- console.log('Session already registered from this device.');
124
- return;
125
- }
126
- }
127
- const newSessionData = {
128
- uid: sessionId,
129
- userId: user.uid,
130
- device: this.getDeviceIdentifier(),
131
- createdAt: new Date().toISOString(),
132
- last_changed: new Date().toISOString(),
133
- status: "online"
134
- };
135
- sessionDatas.push(newSessionData);
136
- await set(userSessionsRef, { sessionDatas });
137
- }
138
107
  }
139
108
  export const firekitAuth = FirekitAuth.getInstance();
@@ -15,7 +15,9 @@ class FirekitDoc {
15
15
  ? doc(firestore, ref)
16
16
  : ref;
17
17
  onSnapshot(this.docRef, (snapshot) => {
18
- this._data = snapshot.data() ?? null;
18
+ // this._data = (snapshot.data() as T) ?? null;
19
+ const data = snapshot.data();
20
+ this._data = data ? { ...data, id: snapshot.id } : null;
19
21
  this._loading = false;
20
22
  this._error = null;
21
23
  }, (error) => {
@@ -27,17 +27,20 @@ class FirekitDocumentMutations {
27
27
  try {
28
28
  const firestore = firebaseService.getDbInstance();
29
29
  const colRef = collection(firestore, collectionPath);
30
- const dataToAdd = {
30
+ let dataToAdd = {
31
31
  ...data,
32
32
  ...(options.timestamps && this.getTimestampData()),
33
33
  };
34
34
  let docRef;
35
35
  if (options.customId) {
36
36
  docRef = doc(colRef, options.customId);
37
+ dataToAdd = { ...dataToAdd, id: docRef.id }; // Agregar el id al documento
37
38
  await setDoc(docRef, dataToAdd);
38
39
  }
39
40
  else {
40
41
  docRef = await addDoc(colRef, dataToAdd);
42
+ dataToAdd = { ...dataToAdd, id: docRef.id }; // Agregar el id al documento
43
+ await setDoc(docRef, dataToAdd);
41
44
  }
42
45
  return {
43
46
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-firekit",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",