-
Notifications
You must be signed in to change notification settings - Fork 240
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
Q: current_user
is not set
#86
Comments
Another question I have is what is a good way of just checking if the token is still good? Basically, I just wanted to sign in with a token and check if it returns back a user which is why I have my index returning current_user if they are signed in. |
Hi @killerham, I'm not sure to understand your first question, but since it has to do with On how you can look at the authentication tokens, you can is to inspect the records from a Rails console: rails console
2.1.1 :001 > User.all.map{|user| {id: user.id, authentication_token: user.authentication_token} }
# User Load (1.7ms) SELECT "users".* FROM "users"
# => [{:id=>1, :authentication_token=>"cr7JqW-_asasdfeapRh"},
# {:id=>3, :authentication_token=>"wmvRmm-5pi9c2kGQm3NW"},
# {:id=>2, :authentication_token=>"rMKz3mflfapBfGS4MtaDQ"}] |
Whoops, forgot to reply. It was because I was using the API controller. The issue/branch from here: #54 fixed my issue. |
Ok @killerham, thanks for your feedback! |
@feliperaul wrote in #188:
|
Hi @feliperaul,
Yes, that's right.
As you noticed, the errors are a consequence of
Do you mean if you remove the reference to Just to cross-check that, I could you It doesn't make sense to me that If Try moving the |
By the way, I think it's more than worth re-opening this issue! |
@gonzalo-bulnes Taking a look at it ! |
I don't know if I am experiencing the same issue, but I am seeing inconsistent results with My controller has endpoints for 1). checking the existence of a class Api::V2::SessionsController < Devise::SessionsController
acts_as_token_authentication_handler_for User
skip_before_filter :verify_authenticity_token, only: [:create, :destroy]
skip_filter :verify_signed_out_user, only: [:destroy]
respond_to :json
def index
if current_user
render json: { logged_in: true, user: current_user }
else
render json: { logged_in: false }
end
end
def create
self.resource = warden.authenticate!(auth_options)
if sign_in(resource_name, resource)
render json: current_user
else
render json: {}, status: 400
end
end
def destroy
if current_user
current_user.update authentication_token: nil
signed_out = Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
render json: { logged_out: true }
else
render json: {}, status: 403
end
end
end On the client side, on page load, I call |
So, it turns out that I was storing the user ID (I use ID instead of email) & auth token in the cookie and i didn't namespace the keys (just |
Oh, that's very good to keep an eye on. Thank you for sharing @jamesfzhang. |
My Api is returning nil for current_user when I pass email and token through the header. My session controller sees current_user when creating and destroying a new session.
The text was updated successfully, but these errors were encountered: