问题描述:

I am working on a Rails 5 api project is running on Ruby 2.3.0 and Rails 5.0.0.alpha

I created SessionsController class that overrided Devise::SessionsController

The sign_in method as below

# POST /resource/sign_in

def create

# Devise code

self.resource = warden.authenticate!(auth_options)

# add more code

user = User.find_for_database_authentication(email: user_params[:email])

return invalid_login_attempt unless user

return invalid_login_attempt unless user.valid_password?(user_params[:password])

# reset json token when user request new session

@token = JsonWebToken.encode(user, user.password)

user.json_token = @token

user.save!

sign_in(resource_name, user)

@message = I18n.t 'devise.sessions.signed_in'

yield resource if block_given?

render 'users/token'

end

the sign out method as

# DELETE /resource/sign_out

def destroy

# current_user is nil when went to here

sign_out(resource_name)

@message = I18n.t'devise.sessions.signed_out'

yield if block_given?

render 'users/logout'

end

Before i have run the line

 sign_out(resource_name)

The value of current_user is nil

I do not know the reason.

My understanding is the value must not be nil and its value is user had logged in

How can i fix this?

Thanks

相关阅读:
Top