Home Rails / Devise (Devise token auth) Redirect upon unlocking account
Reply: 1

Rails / Devise (Devise token auth) Redirect upon unlocking account

marting
1#
marting Published in 2017-12-04 20:55:46Z

I'm currently trying to find a way to change my redirection url upon unlocking an account. Currently when an account is locked the user is getting a email to unlock is account but then the te user get redirect on a default url. Since my rails project is an api it would be nice to redirect to my front-end

Started GET "/api/auth/unlock?unlock_token=YvR4nNssxhB9h8hvDAse" for 
127.0.0.1 at 2017-12-04 15:28:08 -0500
Processing by Devise::UnlocksController#show as JSON
Parameters: {"unlock_token"=>"YvR4nNssxhB9h8hvDAse"}
User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE 
"users"."unlock_token" = $1 ORDER BY "users"."id" ASC LIMIT $2  
[["unlock_token", 
"6f3c4d7aa5254e143f89cd7f187e22ce56b11e6abe1f5eb252e34d86ac101908"], 
["LIMIT", 1]]
(0.1ms)  BEGIN
SQL (0.7ms)  UPDATE "users" SET "locked_at" = $1, "failed_attempts" = $2, 
"unlock_token" = $3, "updated_at" = $4 WHERE "users"."id" = $5  
[["locked_at", nil], ["failed_attempts", 0], ["unlock_token", nil], 
["updated_at", "2017-12-04 20:28:08.783744"], ["id", 1]]
(3.4ms)  COMMIT
Redirected to http://localhost:3000/api/auth/sign_in
Completed 302 Found in 17ms (ActiveRecord: 5.0ms)


Started GET "/api/auth/sign_in" for 127.0.0.1 at 2017-12-04 15:28:08 
-0500
Processing by DeviseTokenAuth::SessionsController#new as JSON
[active_model_serializers] Rendered ActiveModel::Serializer::Null with 
Hash (0.14ms)
Completed 405 Method Not Allowed in 2ms (Views: 0.9ms | ActiveRecord: 
0.0ms)


Started GET "/api/auth/sign_in" for 127.0.0.1 at 2017-12-04 15:31:26 
-0500
Processing by DeviseTokenAuth::SessionsController#new as JSON
[active_model_serializers] Rendered ActiveModel::Serializer::Null with 
Hash (0.11ms) 
Completed 405 Method Not Allowed in 1ms (Views: 0.7ms | ActiveRecord: 
0.0ms)
jemonsanto
2#
jemonsanto Reply to 2017-12-07 10:29:43Z

To do any customization with Devise, one must override the default controllers by creating a new controller and inheriting from it in your case that would be Devise::UnlocksController

For example: CustomUnlocksController < Devise::UnlocksController

https://github.com/plataformatec/devise/blob/master/app/controllers/devise/unlocks_controller.rb

Override after_unlock_path_for to the path which you are going to redirect after.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.400394 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO