@edgedev/firebase 1.3.3 → 1.4.1
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 +24 -0
- package/edgeFirebase.ts +49 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -372,6 +372,30 @@ This function allows a user to change their current password while logged in:
|
|
|
372
372
|
edgeFirebase.setPassword("old-password", "new-password");
|
|
373
373
|
```
|
|
374
374
|
|
|
375
|
+
### Password Reset:
|
|
376
|
+
|
|
377
|
+
For users not logged in (like forgotten password). This is a two step process if the project is setup to redirect password resets back to a custom password reset page.
|
|
378
|
+
|
|
379
|
+
Step 1:
|
|
380
|
+
|
|
381
|
+
```javascript
|
|
382
|
+
edgeFirebase.sendPasswordReset('user@edgemarketingdesign.com');
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Step 2: (If the password redirect is setup to go a custom page, you'll need to pull the "oobCode" from the query string and pass that along with the newpassword.)
|
|
386
|
+
|
|
387
|
+
```javascript
|
|
388
|
+
edgeFirebase.passwordReset('NewPassword123','AAaaAABaaaaAAABBBaaaBBBBAaaaaBABAbbaa');
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Update User Meta:
|
|
392
|
+
|
|
393
|
+
A user can update their own meta data when logged in. The object contain meta data will only update/add the keys passed in the object.
|
|
394
|
+
|
|
395
|
+
```javascript
|
|
396
|
+
edgeFirebase.setUserMeta({ lastName: "Smith" });
|
|
397
|
+
```
|
|
398
|
+
|
|
375
399
|
# Firestore Basic Document Interactions
|
|
376
400
|
|
|
377
401
|
### Adding/Update a Document.
|
package/edgeFirebase.ts
CHANGED
|
@@ -36,7 +36,9 @@ import {
|
|
|
36
36
|
createUserWithEmailAndPassword,
|
|
37
37
|
updatePassword,
|
|
38
38
|
reauthenticateWithCredential,
|
|
39
|
-
EmailAuthProvider
|
|
39
|
+
EmailAuthProvider,
|
|
40
|
+
sendPasswordResetEmail,
|
|
41
|
+
confirmPasswordReset
|
|
40
42
|
} from "firebase/auth";
|
|
41
43
|
|
|
42
44
|
interface FirestoreQuery {
|
|
@@ -76,8 +78,6 @@ interface role {
|
|
|
76
78
|
role: "admin" | "user";
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
// TODO: PASSWORD RESET FUNCTION <-- NOT LOGGED IN, AND USER META UPDATE FUNCTION (ONLY FOR THEMSELVES)
|
|
80
|
-
|
|
81
81
|
interface specialPermission {
|
|
82
82
|
collectionPath: "-" | string; // - is root
|
|
83
83
|
permissions: permissions;
|
|
@@ -314,6 +314,40 @@ export const EdgeFirebase = class {
|
|
|
314
314
|
}
|
|
315
315
|
};
|
|
316
316
|
|
|
317
|
+
public sendPasswordReset = async (email: string): Promise<actionResponse> => {
|
|
318
|
+
try {
|
|
319
|
+
await sendPasswordResetEmail(this.auth, email);
|
|
320
|
+
return this.sendResponse({
|
|
321
|
+
success: true,
|
|
322
|
+
message: ""
|
|
323
|
+
});
|
|
324
|
+
} catch (error) {
|
|
325
|
+
return this.sendResponse({
|
|
326
|
+
success: false,
|
|
327
|
+
message: error.message
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
public passwordReset = async (
|
|
333
|
+
password: string,
|
|
334
|
+
oobCode: string
|
|
335
|
+
): Promise<actionResponse> => {
|
|
336
|
+
try {
|
|
337
|
+
// await verifyPasswordResetCode(this.auth, oobCode);
|
|
338
|
+
await confirmPasswordReset(this.auth, oobCode, password);
|
|
339
|
+
return this.sendResponse({
|
|
340
|
+
success: true,
|
|
341
|
+
message: ""
|
|
342
|
+
});
|
|
343
|
+
} catch (error) {
|
|
344
|
+
return this.sendResponse({
|
|
345
|
+
success: false,
|
|
346
|
+
message: error.message
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
317
351
|
public setPassword = async (
|
|
318
352
|
oldpassword: string,
|
|
319
353
|
password: string
|
|
@@ -338,6 +372,18 @@ export const EdgeFirebase = class {
|
|
|
338
372
|
}
|
|
339
373
|
};
|
|
340
374
|
|
|
375
|
+
setUserMeta = async (meta: unknown): Promise<actionResponse> => {
|
|
376
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
377
|
+
await updateDoc(doc(this.db, "users/" + this.user.email), {
|
|
378
|
+
["meta." + key]: value
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return this.sendResponse({
|
|
382
|
+
success: true,
|
|
383
|
+
message: ""
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
|
|
341
387
|
public removeUser = async (email: string): Promise<actionResponse> => {
|
|
342
388
|
const removedFrom = [];
|
|
343
389
|
const userRef = doc(this.db, "users", email);
|
package/package.json
CHANGED