0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Parseで認証用Emailを再送する方法

Posted at

Parseには認証用Emailの再送機能が存在しない

Parseを使えばEmail認証機能が簡単に実装できるのですが、再送機能が存在しないようなので困りました。

検索すると2年程前の公式フォーラムでのやりとりがいくつか引っかかるのですが、そこではUserテーブルのemailカラムを更新すれば同じ値で更新したとしても送信されると中の人が答えています。
しかし実際は同じ値だと送信されないようです。
中の人は送信されると言い張っているのですが、僕も試したところ送信されませんでした。

なので、一度空にしてから元の値に更新するという方法で実装してみました。

Client側(JavaScript SDK)

    Parse.Cloud.run('resendEmailVerification', {})
    .then(function(result) {
        console.log(result);
    }, function(error) {
        console.error(error);
    });

Server側(Cloud Code)

Parse.Cloud.define("resendEmailVerification", function(request, response) {

    var user = request.user;
    var email = user.get("email");
    user.set("email", "");
    user.save()
    .then(function() {
        user.set("email", email);
        return user.save();
    })
    .then(function() {
        response.success("Successfully resent verification email.");
    }, function(error) {
        //emailの削除だけが成功した場合はよろしくない・・・
        response.error("RESEND_VERIFICATION_EMAIL_FAILED");
    });

});

Cloud Codeは使わずにすべてClient側でやってしまってもいいのですが、以下で説明するようなエラー対応はServer側の方がやりやすいと思います。

2度目の更新でコケるとuserのemailが空になってしまう

空の値で更新->元の値で更新という2段階を経ているのですが、2つ目がコケた時はそのuserのemailカラムが空になってしまいます。

そうなると運営側で対応するしかなくなるので、元のEmailとuserIdをログに吐いたりエラー通知をメールで飛ばすようにする等の対応が必要かもしれません。

再送機能は必要としている人が多そうなのでParse側で実装して欲しいですね。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?