LoginSignup
8
3

More than 5 years have passed since last update.

devise_token_authでメール認証をアクティブ化できなかった

Posted at

なかなか発見できなくて詰まったので備忘録的に残しておく。

devise_token_auth 利用時にemailでの認証を追加するときに大きく詰まった。やりたいことは単純で以下の2ステップ。

  1. mailcatcher環境をローカル構築
  2. deviseでメール認証を可能に

順にまとめていく。

mailcatcher環境の構築

mailcatcherの説明は次の通り

MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.

試したこと

readmeに書かれている通りの手順で構築できるかをまずは試した。しかしこれは失敗。mailcatcherはうまく立ち上がるんだけど、sinatraを入れたせいで、rails sercerコマンドを叩くとエラーが出るように。確かにわざわざrails環境で用意する必要も無いと思ったので、違う方法を考えることにした。(この辺詳しい人いたら教えて欲しいです。。)

実際の環境

git clone https://github.com/sj26/mailcatcher.git
cd mailcatcher
bundle 
bundle exec ./bin/mailcatcher -f

もしもうまくいかなかった場合は、

bundle install sinatra でsinatraをインストールしてもう一回試してみることをおすすめします。

この手順に沿っていけば、smtpサーバーが構築できる。アドレスは最後のコマンドを実行した時に出力される以下。httpの方は送信されたメールを確認するブラウザ。

smtp://127.0.0.1:1025
http://127.0.0.1:1080

とはいっても、何故か僕の環境では、うまくブラウザ経由でみれなかったので、以下のコマンドからAPI経由で確認している。

curl -s localhost:1080/messages

# [{"id":1,"sender":"<from@example.com>","recipients":["<to_address@example.com>"],"subject":"test subject","size":"290","created_at":"2017-02-12T07:43:54+00:00"},{"id":2,"sender":"<from@example.com>","recipients":["<to_address@example.com>"],"subject":"test subject","size":"289","created_at":"2017-02-12T07:44:46+00:00"}]

これでmailcatcher環境が構築できたので、次はdevise_token_auth側の設定

devise_token_auth側の設定

ありがちなエラーみたいで、色んな情報が載っていて振り回されまくった。ちなみにずっと出てたエラーは以下

Unpermitted parameter: registration

「お、ストロングパラメーター関係やーん!」って思って色々ぐぐってたけど、結局全然違った。

解決方法

僕の解決方法は次の通り。

config/initializers/devise_token_auth.rb
  # 以下を追加
  config.default_confirm_success_url = "confirmed"

以上!ストロングパラメーターでもなんでもなかった。こいつはここに書かれているパラメーターなんだけど、これを設定することで全てが解決した。

8
3
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
8
3