@mohasinac/appkit 4.6.1 → 4.6.2
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.
|
@@ -14,6 +14,8 @@ export declare class FirebaseClientAuthProvider implements IClientAuthProvider {
|
|
|
14
14
|
applyActionCode(code: string): Promise<void>;
|
|
15
15
|
sendPasswordResetEmail(email: string): Promise<void>;
|
|
16
16
|
confirmPasswordReset(code: string, newPassword: string): Promise<void>;
|
|
17
|
+
/** Re-authenticates the current user against `currentPassword`, returning the now-fresh user. Throws if no user is signed in. */
|
|
18
|
+
private _reauthenticate;
|
|
17
19
|
reauthenticateAndChangePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
18
20
|
reauthenticateOnly(currentPassword: string): Promise<void>;
|
|
19
21
|
reauthenticateAndSendEmailUpdateVerification(currentPassword: string, newEmail: string): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { applyActionCode as fbApplyActionCode, confirmPasswordReset as fbConfirmPasswordReset, EmailAuthProvider, reauthenticateWithCredential, sendPasswordResetEmail as fbSendPasswordResetEmail, signInWithEmailAndPassword as fbSignInWithEmailAndPassword, updatePassword, verifyBeforeUpdateEmail, } from "firebase/auth";
|
|
2
|
+
const NO_AUTHENTICATED_USER_MESSAGE = "No authenticated user.";
|
|
2
3
|
/**
|
|
3
4
|
* Firebase Auth client SDK implementation of IClientAuthProvider.
|
|
4
5
|
*
|
|
@@ -22,27 +23,24 @@ export class FirebaseClientAuthProvider {
|
|
|
22
23
|
async confirmPasswordReset(code, newPassword) {
|
|
23
24
|
await fbConfirmPasswordReset(this._auth, code, newPassword);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
/** Re-authenticates the current user against `currentPassword`, returning the now-fresh user. Throws if no user is signed in. */
|
|
27
|
+
async _reauthenticate(currentPassword) {
|
|
26
28
|
const user = this._auth.currentUser;
|
|
27
29
|
if (!user?.email)
|
|
28
|
-
throw new Error(
|
|
30
|
+
throw new Error(NO_AUTHENTICATED_USER_MESSAGE);
|
|
29
31
|
const credential = EmailAuthProvider.credential(user.email, currentPassword);
|
|
30
32
|
await reauthenticateWithCredential(user, credential);
|
|
33
|
+
return user;
|
|
34
|
+
}
|
|
35
|
+
async reauthenticateAndChangePassword(currentPassword, newPassword) {
|
|
36
|
+
const user = await this._reauthenticate(currentPassword);
|
|
31
37
|
await updatePassword(user, newPassword);
|
|
32
38
|
}
|
|
33
39
|
async reauthenticateOnly(currentPassword) {
|
|
34
|
-
|
|
35
|
-
if (!user?.email)
|
|
36
|
-
throw new Error("No authenticated user.");
|
|
37
|
-
const credential = EmailAuthProvider.credential(user.email, currentPassword);
|
|
38
|
-
await reauthenticateWithCredential(user, credential);
|
|
40
|
+
await this._reauthenticate(currentPassword);
|
|
39
41
|
}
|
|
40
42
|
async reauthenticateAndSendEmailUpdateVerification(currentPassword, newEmail) {
|
|
41
|
-
const user = this.
|
|
42
|
-
if (!user?.email)
|
|
43
|
-
throw new Error("No authenticated user.");
|
|
44
|
-
const credential = EmailAuthProvider.credential(user.email, currentPassword);
|
|
45
|
-
await reauthenticateWithCredential(user, credential);
|
|
43
|
+
const user = await this._reauthenticate(currentPassword);
|
|
46
44
|
await verifyBeforeUpdateEmail(user, newEmail);
|
|
47
45
|
}
|
|
48
46
|
async reloadCurrentUser() {
|