简体   繁体   中英

Rails Devise-JWT, how to configure devise.rb to add a dispatch_requests

I'm using devise-jwt

The readme has the following:

dispatch_requests: "additional requests where JWT tokens should be dispatched"

Example:

jwt.dispatch_requests = [
                          ['POST', %r{^/dispatch_path_1$}],
                          ['GET', %r{^/dispatch_path_2$}],
                        ]

Based on the doc, I updated my devise.rb with the following:

  config.jwt do |jwt|
    jwt.secret = ENV['DEVISE_JWT_SECRET_KEY']
    jwt.expiration_time = 30.days
    jwt.dispatch_requests = [
                              ['GET', %r{^/users/confirmation.*$}]
                            ]
  end

With the goal of getting devise-jwt to dispatch the JWT token when a user confirms their email address via email by clicking the following link:

http://localhost:4400/users/confirmation?confirmation_token=16J2zDtDhjyF3vCQv2ba

For some reason, the above URL is not getting the JWT token dispatched in the header... Given I'm horrible at regex, I'm hoping for some help... Did I do something wrong to add the additional dispatch request in my devise config?

Thank you!

If the token is in the link you click on then the token won't be in the header, it will be sent as a param called 'confirmation_token'. which you would access as: params[:confirmation_token] from within the controller.

ps JSON web tokens are awesome, I like using them to manage state in an application so no need for session storage :D, of course this does present a slight issue when you need to access data within token on the front end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM