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

Commit

Permalink
Send Email Verification #214
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Nov 20, 2016
1 parent 230106c commit 96c1fef
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/AUTHENTICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,18 @@ Shouldn't be more complicated than:
```


### sendEmailVerification
Sending an "email confirmation" email can be done after the user logged in:

```js
firebase.sendEmailVerification().then(
function () {
console.log("Email verification sent);
},
function (error) {
console.log("Error sending email verification: " + error);
}
);
```
32 changes: 32 additions & 0 deletions firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,38 @@ firebase.getCurrentUser = function (arg) {
});
};

firebase.sendEmailVerification = function () {
return new Promise(function (resolve, reject) {
try {
if (firebase.instance === null) {
reject("Run init() first!");
return;
}

var firebaseAuth = com.google.firebase.auth.FirebaseAuth.getInstance();
var user = firebaseAuth.getCurrentUser();
if (user !== null) {
var addOnCompleteListener = new com.google.android.gms.tasks.OnCompleteListener({
onComplete: function(task) {
if (!task.isSuccessful()) {
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
} else {
resolve();
}
}
});

user.sendEmailVerification().addOnCompleteListener(addOnCompleteListener);
} else {
reject("Log in first");
}
} catch (ex) {
console.log("Error in firebase.sendEmailVerification: " + ex);
reject(ex);
}
});
};

firebase.logout = function (arg) {
return new Promise(function (resolve, reject) {
try {
Expand Down
29 changes: 29 additions & 0 deletions firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,35 @@ firebase.getCurrentUser = function (arg) {
});
};

firebase.sendEmailVerification = function () {
return new Promise(function (resolve, reject) {
try {
var fAuth = FIRAuth.auth();
if (fAuth === null) {
reject("Run init() first!");
return;
}

var user = fAuth.currentUser;
if (user) {
var onCompletion = function(error) {
if (error) {
reject(error.localizedDescription);
} else {
resolve(true);
}
};
user.sendEmailVerificationWithCompletion(onCompletion);
} else {
reject("Log in first");
}
} catch (ex) {
console.log("Error in firebase.sendEmailVerification: " + ex);
reject(ex);
}
});
};

firebase.logout = function (arg) {
return new Promise(function (resolve, reject) {
try {
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ export function getAuthToken(option: GetAuthTokenOptions): Promise<string>;

export function logout(): Promise<any>;

export function sendEmailVerification(): Promise<any>;

export function createUser(options: CreateUserOptions): Promise<CreateUserResult>;

export function deleteUser(): Promise<any>;
Expand Down

0 comments on commit 96c1fef

Please sign in to comment.