‘Confirmation token is invalid’ when confirming after registering in Devise gem

I got stuck for sometime by getting the issue.

When registering a new user with :confirmable in my devise user model, when the user clicks on the e-mail confirmation link, they receive an “Invalid confirmation token” error message

Found some solution by searching about this,

config.allow_insecure_token_lookup = true (Never do it in your devise initilizer because it’s a security threat)

NOTE: This problem only arising in Devise version 3.1.X

So i have fixed the issue only by changing in the below file,

app/views/devise/mailer/confirmation_instructions.html.erb

Replace,

<%= link_to ‘Confirm my account’, user_confirmation_url(:confirmation_token => @resource.confirmation_token) %>

with

<%= link_to ‘Confirm my new account’, confirmation_url(@resource, :confirmation_token => @token) %>

Just replace the old token from resource with the new instance variable @token

Hope it will help you out.

Advertisements

One thought on “‘Confirmation token is invalid’ when confirming after registering in Devise gem

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s