-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No token on response header #721
Comments
Hey, |
Guys, can you post your config/routes.rb and the custom controller implementation if any. I haven't had any of those issues. |
My config/routes.rb looks like this ...
devise_for :users, controllers: {
sessions: 'users/sessions',
confirmations: 'users/confirmations'
}
namespace :api, defaults: {format: :json} do
namespace :v1 do
mount_devise_token_auth_for 'User', at: 'auth'
end
end
... I've made the following base controller for my API class Api::V1::BaseController < ApplicationController
include DeviseTokenAuth::Concerns::SetUserByToken
respond_to :json
before_action :authenticate_user!
end And this is my ApplicationController class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
end
end I'm using devise for my non API authentications and it seems to work fine. |
@rahulnwn I'm not clear on how you solved the problem. Can you explain a with a little more detail the steps you did? |
Hi again. I finally solved this issue. The problem was similar to the description given by @rahulnwn. To find the issue I did the following. First, I overridden the Sessions controller with the following controller class DeviseTokenAuthOverrides::SessionsController < DeviseTokenAuth::SessionsController
def render_create_success
render json: {data: @resource.errors}
end
end With this, I noticed that the output on a successful login was this, eventhough I did provide an email and password on the login request. {
"data": {
"password": [
"can't be blank"
]
}
} I checked my User model and noticed that I was validating that the field "password" wasn't blank, so removing that line solved the issue. Hope this might be useful to some having similar problems |
Just to clear things up a bit (word the answer above in a different way), this happens if you added a validation to your user model that your previous model instances don't meet. i.e. I added a validation that my users would have an avatar (image) and the users already in my database didn't have an image but when I logged in with them it would still give me a successful login, status 200, but wouldn't return the headers. Solution: Remove the validation if it's not necessary or make your previously created instance of the model meet the validation by either running a script inserting the necessary data or manually updating them through the console. |
I hit the same issue. If something craps out or doesn't render. the headers are not sent. in my case it was that there was nothing to render. this stopped the headers from being set for some odd reason. it seems to me every response, even a 500/404/whatever, as long as the token sent is valid, should include the new token header coming back. |
Workarounds posted, closing for now. |
Hi. I'm trying to make this gem work, but when I try to do an email login with Postman or curl, even if the login is successful I can't get the access-token or any of the other fields on the header response. I'm just getting user data.
The response header looks like this
My Gemfile looks like this
Thanks in advance for any help on this subject
The text was updated successfully, but these errors were encountered: