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

Commit f5bd366

Browse files
committed
Implement changePassword feature
1 parent 4917d67 commit f5bd366

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,23 @@ You can expect more login mechanisms to be added in the future.
264264
}).then(
265265
function () {
266266
// called when password reset was successful,
267-
// you ccould now prompt the user to check his email
267+
// you could now prompt the user to check his email
268+
},
269+
function (errorMessage) {
270+
console.log(errorMessage);
271+
}
272+
)
273+
```
274+
275+
#### Changing a password
276+
```js
277+
firebase.changePassword({
278+
279+
oldPassword: 'myOldPassword',
280+
newPassword: 'myNewPassword'
281+
}).then(
282+
function () {
283+
// called when password change was successful,
268284
},
269285
function (errorMessage) {
270286
console.log(errorMessage);

firebase.android.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,30 @@ firebase.resetPassword = function (arg) {
158158
});
159159
};
160160

161+
firebase.changePassword = function (arg) {
162+
return new Promise(function (resolve, reject) {
163+
try {
164+
var resultHandler = new com.firebase.client.Firebase.ResultHandler({
165+
onSuccess: function () {
166+
resolve();
167+
},
168+
onError: function (firebaseError) {
169+
reject(firebaseError.getMessage());
170+
}
171+
});
172+
173+
if (!arg.email || !arg.oldPassword || !arg.newPassword) {
174+
reject("Changing a password requires an email and an oldPassword and a newPassword arguments");
175+
} else {
176+
instance.changePassword(arg.email, arg.oldPassword, arg.newPassword, resultHandler);
177+
}
178+
} catch (ex) {
179+
console.log("Error in firebase.changePassword: " + ex);
180+
reject(ex);
181+
}
182+
});
183+
};
184+
161185
firebase.createUser = function (arg) {
162186
return new Promise(function (resolve, reject) {
163187
try {

firebase.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,20 @@ declare module "nativescript-plugin-firebase" {
110110
value: any;
111111
}
112112

113+
/**
114+
* The options object passed into the changePassword function.
115+
*/
116+
export interface ChangePasswordOptions {
117+
email: string;
118+
oldPassword: string;
119+
newPassword: string
120+
}
121+
113122
export function init(options: InitOptions): Promise<any>;
114123
export function login(options: LoginOptions): Promise<LoginResult>;
115124
export function createUser(options: CreateUserOptions): Promise<CreateUserResult>;
116125
export function resetPassword(options: ResetPasswordOptions): Promise<any>;
126+
export function changePassword(options: ChangePasswordOptions): Promise<any>;
117127
export function push(path: string, value: any): Promise<PushResult>;
118128
export function setValue(path: string, value: any): Promise<any>;
119129
export function update(path: string, value: any): Promise<any>;

firebase.ios.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ firebase.resetPassword = function (arg) {
123123
});
124124
};
125125

126+
firebase.changePassword = function (arg) {
127+
return new Promise(function (resolve, reject) {
128+
try {
129+
var onCompletion = function(error) {
130+
if (error) {
131+
reject(error.localizedDescription);
132+
} else {
133+
resolve();
134+
}
135+
};
136+
137+
if (!arg.email || !arg.oldPassword || !arg.newPassword) {
138+
reject("Changing a password requires an email and an oldPassword and a newPassword arguments");
139+
} else {
140+
instance.changePasswordForUserFromOldToNewWithCompletionBlock(arg.email, arg.oldPassword, arg.newPassword, onCompletion);
141+
}
142+
} catch (ex) {
143+
console.log("Error in firebase.changePassword: " + ex);
144+
reject(ex);
145+
}
146+
});
147+
};
148+
126149
firebase.createUser = function (arg) {
127150
return new Promise(function (resolve, reject) {
128151
try {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"description" : "Fire. Base. Firebase!",
55
"main" : "firebase.js",
66
"nativescript": {

0 commit comments

Comments
 (0)