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

Commit 163721b

Browse files
Couldn't find Manage User functions #1080 (added Web API support for 'resetPassword', and added 'updateEmail')
1 parent 604af98 commit 163721b

7 files changed

Lines changed: 411 additions & 228 deletions

File tree

demo/app/main-page.xml

Lines changed: 101 additions & 94 deletions
Large diffs are not rendered by default.

demo/app/main-view-model.ts

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,28 @@ export class HelloWorldModel extends Observable {
11601160
}
11611161

11621162
public doResetPassword(): void {
1163-
firebase.resetPassword({
1164-
email: 'eddyverbruggen@gmail.com'
1165-
}).then(
1163+
firebase.sendPasswordResetEmail("eddyverbruggen@gmail.com").then(
1164+
() => {
1165+
console.log("Password reset. Check your email.");
1166+
this.set("userEmailOrPhone", "Password reset mail sent to eddyverbruggen@gmail.com.");
1167+
alert({
1168+
title: "Password reset. Check your email.",
1169+
okButtonText: "OK, nice!"
1170+
});
1171+
},
1172+
error => {
1173+
console.log("Password reset error: " + error);
1174+
alert({
1175+
title: "Password reset error",
1176+
message: error,
1177+
okButtonText: "Hmmkay :("
1178+
});
1179+
}
1180+
);
1181+
}
1182+
1183+
public doWebResetPassword(): void {
1184+
firebaseWebApi.auth().sendPasswordResetEmail("eddyverbruggen@gmail.com").then(
11661185
() => {
11671186
console.log("Password reset. Check your email.");
11681187
this.set("userEmailOrPhone", "Password reset mail sent to eddyverbruggen@gmail.com.");
@@ -1182,6 +1201,90 @@ export class HelloWorldModel extends Observable {
11821201
);
11831202
}
11841203

1204+
public doUpdateEmail(): void {
1205+
firebase.updateEmail("eddyverbruggen+firebase@gmail.com").then(
1206+
() => {
1207+
console.log("Email updated.");
1208+
this.set("userEmailOrPhone", "Email updated to eddyverbruggen+firebase@gmail.com");
1209+
alert({
1210+
title: "Email updated.",
1211+
okButtonText: "OK, nice!"
1212+
});
1213+
},
1214+
error => {
1215+
console.log("Email update error: " + error);
1216+
alert({
1217+
title: "Email update error",
1218+
message: error,
1219+
okButtonText: "Hmmkay :("
1220+
});
1221+
}
1222+
);
1223+
}
1224+
1225+
public doWebUpdateEmail(): void {
1226+
firebaseWebApi.auth().updateEmail("eddyverbruggen+firebase@gmail.com").then(
1227+
() => {
1228+
console.log("Email updated.");
1229+
this.set("userEmailOrPhone", "Email updated to eddyverbruggen+firebase@gmail.com");
1230+
alert({
1231+
title: "Email updated.",
1232+
okButtonText: "OK, nice!"
1233+
});
1234+
},
1235+
error => {
1236+
console.log("Email update error: " + error);
1237+
alert({
1238+
title: "Email update error",
1239+
message: error,
1240+
okButtonText: "Hmmkay :("
1241+
});
1242+
}
1243+
);
1244+
}
1245+
1246+
public doUpdatePassword(): void {
1247+
firebase.updatePassword("pwd123LOL").then(
1248+
() => {
1249+
console.log("Password updated.");
1250+
this.set("userEmailOrPhone", "Password updated to pwd123LOL");
1251+
alert({
1252+
title: "Password updated.",
1253+
okButtonText: "OK, nice!"
1254+
});
1255+
},
1256+
error => {
1257+
console.log("Password update error: " + error);
1258+
alert({
1259+
title: "Password update error",
1260+
message: error,
1261+
okButtonText: "Hmmkay :("
1262+
});
1263+
}
1264+
);
1265+
}
1266+
1267+
public doWebUpdatePassword(): void {
1268+
firebaseWebApi.auth().updatePassword("pwd123LOL").then(
1269+
() => {
1270+
console.log("Password updated.");
1271+
this.set("userEmailOrPhone", "Password updated to pwd123LOL");
1272+
alert({
1273+
title: "Password updated.",
1274+
okButtonText: "OK, nice!"
1275+
});
1276+
},
1277+
error => {
1278+
console.log("Password update error: " + error);
1279+
alert({
1280+
title: "Password update error",
1281+
message: error,
1282+
okButtonText: "Hmmkay :("
1283+
});
1284+
}
1285+
);
1286+
}
1287+
11851288
public doSendEmailVerification(): void {
11861289
firebase.sendEmailVerification().then(
11871290
() => {

docs/AUTHENTICATION.md

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -365,50 +365,73 @@ This may not work on an (Android) simulator. See #463.
365365

366366

367367
#### Resetting a password
368-
```js
369-
firebase.resetPassword({
370-
email: 'useraccount@provider.com'
371-
}).then(
372-
function () {
373-
// called when password reset was successful,
374-
// you could now prompt the user to check his email
375-
},
376-
function (errorMessage) {
377-
console.log(errorMessage);
378-
}
379-
);
368+
> The method name and signature has changed in 8.0.0 from `resetPassword` to `sendPasswordResetEmail` to better align with the Web API.
369+
370+
<details>
371+
<summary>Native API</summary>
372+
373+
```typescript
374+
firebase.sendPasswordResetEmail("user@example.com")
375+
.then(() => console.log("Password reset email sent"))
376+
.catch(error => console.log("Error sending password reset email: " + error));
380377
```
378+
</details>
381379

382-
#### Updating a password
380+
<details>
381+
<summary>Web API</summary>
382+
383+
```typescript
384+
firebaseWebApi.auth().sendPasswordResetEmail("user@example.com")
385+
.then(() => console.log("Password reset email sent"))
386+
.catch(error => console.log("Error sending password reset email: " + error));
387+
```
388+
</details>
389+
390+
#### Updating an email address
391+
Note that changing an email address may fail if your login for this `email` was too long ago (per Firebase's standards, whatever they are).
392+
393+
<details>
394+
<summary>Native API</summary>
395+
396+
```typescript
397+
firebase.updateEmail("user@example.com")
398+
.then(() => console.log("Email updated"))
399+
.catch(error => console.log("Error updating email: " + error));
400+
```
401+
</details>
402+
403+
<details>
404+
<summary>Web API</summary>
405+
406+
```typescript
407+
firebaseWebApi.auth().updateEmail("user@example.com")
408+
.then(() => console.log("Email updated"))
409+
.catch(error => console.log("Error updating email: " + error));
410+
```
411+
</details>
383412

384-
> The method name was changed in 8.0.0 from `changePassword` to `updatePassword` to better align with the Web API.
413+
#### Updating a password
414+
> The method name and signature has changed in 8.0.0 from `changePassword` to `updatePassword` to better align with the Web API.
385415
386416
Note that changing a password may fail if your login for this `email` was too long ago (per Firebase's standards, whatever they are).
387417

388418
<details>
389419
<summary>Native API</summary>
390420

391-
```js
392-
firebase.updatePassword({
393-
newPassword: 'myNewPassword'
394-
}).then(
395-
function () {
396-
// called when password change was successful
397-
},
398-
function (errorMessage) {
399-
console.log(errorMessage);
400-
}
401-
);
421+
```typescript
422+
firebase.updatePassword("myNewPassword")
423+
.then(() => console.log("Password updated"))
424+
.catch(error => console.log("Error updating password: " + error));
402425
```
403426
</details>
404427

405428
<details>
406429
<summary>Web API</summary>
407430

408431
```typescript
409-
firebaseWebApi.auth().updatePassword('new-password')
432+
firebaseWebApi.auth().updatePassword("myNewPassword")
410433
.then(() => console.log("Password updated"))
411-
.catch(error => console.log("Error creating user: " + error));
434+
.catch(error => console.log("Error updating password: " + error));
412435
```
413436
</details>
414437

src/app/auth/index.ts

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

119+
public updateEmail(newEmail: string): Promise<void> {
120+
return new Promise<void>((resolve, reject) => {
121+
firebase.updateEmail(newEmail)
122+
.then(() => resolve())
123+
.catch(err => reject(err));
124+
})
125+
}
126+
119127
public updatePassword(newPassword: string): Promise<void> {
120128
return new Promise<void>((resolve, reject) => {
121-
firebase.changePassword(
122-
{
123-
newPassword
124-
})
129+
firebase.updatePassword(newPassword)
130+
.then(() => resolve())
131+
.catch(err => reject(err));
132+
})
133+
}
134+
135+
public sendPasswordResetEmail(email: string): Promise<void> {
136+
return new Promise<void>((resolve, reject) => {
137+
firebase.sendPasswordResetEmail(email)
125138
.then(() => resolve())
126139
.catch(err => reject(err));
127140
})

0 commit comments

Comments
 (0)