Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit f89c6be

Browse files
Couldn't find Manage User functions #1080 (added Web API support for 'updatePassword')
1 parent b833b1b commit f89c6be

4 files changed

Lines changed: 42 additions & 45 deletions

File tree

src/app/auth/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ export module auth {
116116
})
117117
}
118118

119+
public updatePassword(newPassword: string): Promise<void> {
120+
return new Promise<void>((resolve, reject) => {
121+
firebase.changePassword(
122+
{
123+
newPassword
124+
})
125+
.then(() => resolve())
126+
.catch(err => reject(err));
127+
})
128+
}
129+
119130
public signInAnonymously(): Promise<any> {
120131
return new Promise((resolve, reject) => {
121132
firebase.login({

src/firebase.android.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
import * as appModule from "tns-core-modules/application";
2+
import { AndroidActivityResultEventData } from "tns-core-modules/application";
3+
import lazy from "tns-core-modules/utils/lazy";
4+
import { ad as AndroidUtils } from "tns-core-modules/utils/utils";
5+
import { ChangePasswordOptions, DataSnapshot, firestore, OnDisconnect as OnDisconnectBase, User } from "./firebase";
16
import {
27
DocumentSnapshot as DocumentSnapshotBase,
38
FieldValue,
49
firebase,
510
GeoPoint,
611
isDocumentReference
712
} from "./firebase-common";
8-
import * as firebaseMessaging from "./messaging/messaging";
913
import * as firebaseFunctions from "./functions/functions";
10-
import * as appModule from "tns-core-modules/application";
11-
import { AndroidActivityResultEventData } from "tns-core-modules/application";
12-
import { ad as AndroidUtils } from "tns-core-modules/utils/utils";
13-
import lazy from "tns-core-modules/utils/lazy";
14-
import { firestore, User, OnDisconnect as OnDisconnectBase, DataSnapshot } from "./firebase";
14+
import * as firebaseMessaging from "./messaging/messaging";
1515

1616
declare const com: any;
1717
const gmsAds = (<any>com.google.android.gms).ads;
@@ -1207,29 +1207,25 @@ firebase.resetPassword = arg => {
12071207
});
12081208
};
12091209

1210-
firebase.changePassword = arg => {
1211-
return new Promise((resolve, reject) => {
1210+
firebase.changePassword = (arg: ChangePasswordOptions): Promise<void> => {
1211+
return new Promise<void>((resolve, reject) => {
12121212
try {
1213-
if (!arg.email || !arg.oldPassword || !arg.newPassword) {
1214-
reject("Changing a password requires an email and an oldPassword and a newPassword arguments");
1215-
} else {
1216-
const onCompleteListener = new gmsTasks.OnCompleteListener({
1217-
onComplete: task => {
1218-
if (task.isSuccessful()) {
1219-
resolve();
1220-
} else {
1221-
reject("Updating password failed. " + (task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
1222-
}
1213+
const onCompleteListener = new gmsTasks.OnCompleteListener({
1214+
onComplete: task => {
1215+
if (task.isSuccessful()) {
1216+
resolve();
1217+
} else {
1218+
reject("Updating password failed. " + (task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
12231219
}
1224-
});
1220+
}
1221+
});
12251222

1226-
const user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
1223+
const user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
12271224

1228-
if (user === null) {
1229-
reject("no current user");
1230-
} else {
1231-
user.updatePassword(arg.newPassword).addOnCompleteListener(onCompleteListener);
1232-
}
1225+
if (user === null) {
1226+
reject("no current user");
1227+
} else {
1228+
user.updatePassword(arg.newPassword).addOnCompleteListener(onCompleteListener);
12331229
}
12341230
} catch (ex) {
12351231
console.log("Error in firebase.changePassword: " + ex);

src/firebase.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,7 @@ export interface FBData {
401401
value: any;
402402
}
403403

404-
/**
405-
* The options object passed into the changePassword function.
406-
*/
407404
export interface ChangePasswordOptions {
408-
email: string;
409-
oldPassword: string;
410405
newPassword: string;
411406
}
412407

@@ -909,7 +904,7 @@ export function updateProfile(options: UpdateProfileOptions): Promise<any>;
909904

910905
export function resetPassword(options: ResetPasswordOptions): Promise<any>;
911906

912-
export function changePassword(options: ChangePasswordOptions): Promise<any>;
907+
export function changePassword(options: ChangePasswordOptions): Promise<void>;
913908

914909
export function addAuthStateListener(listener: AuthStateChangeListener): boolean;
915910

src/firebase.ios.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { iOSApplication } from "tns-core-modules/application/application";
1+
import * as application from "tns-core-modules/application/application";
2+
import { ChangePasswordOptions, DataSnapshot, firestore, OnDisconnect as OnDisconnectBase, User } from "./firebase";
23
import {
34
DocumentSnapshot as DocumentSnapshotBase,
45
FieldValue,
56
firebase,
67
GeoPoint,
78
isDocumentReference
89
} from "./firebase-common";
9-
import * as firebaseMessaging from "./messaging/messaging";
10-
import * as application from "tns-core-modules/application/application";
1110
import * as firebaseFunctions from './functions/functions';
12-
import { firestore, User, OnDisconnect as OnDisconnectBase, DataSnapshot } from "./firebase";
11+
import * as firebaseMessaging from "./messaging/messaging";
1312
import { firebaseUtils } from "./utils";
1413

1514
firebase._gIDAuthentication = null;
@@ -1097,8 +1096,8 @@ firebase.resetPassword = arg => {
10971096
});
10981097
};
10991098

1100-
firebase.changePassword = arg => {
1101-
return new Promise((resolve, reject) => {
1099+
firebase.changePassword = (arg: ChangePasswordOptions): Promise<void> => {
1100+
return new Promise<void>((resolve, reject) => {
11021101
try {
11031102
const onCompletion = error => {
11041103
if (error) {
@@ -1108,15 +1107,11 @@ firebase.changePassword = arg => {
11081107
}
11091108
};
11101109

1111-
if (!arg.email || !arg.oldPassword || !arg.newPassword) {
1112-
reject("Changing a password requires an email and an oldPassword and a newPassword arguments");
1110+
const user = FIRAuth.auth().currentUser;
1111+
if (user === null) {
1112+
reject("no current user");
11131113
} else {
1114-
const user = FIRAuth.auth().currentUser;
1115-
if (user === null) {
1116-
reject("no current user");
1117-
} else {
1118-
user.updatePasswordCompletion(arg.newPassword, onCompletion);
1119-
}
1114+
user.updatePasswordCompletion(arg.newPassword, onCompletion);
11201115
}
11211116
} catch (ex) {
11221117
console.log("Error in firebase.changePassword: " + ex);

0 commit comments

Comments
 (0)