ruby on rails 4 - Devise remember_me! not working -


i have following code in sessions_controller.rb file:

module v1   class users::sessionscontroller < devise::sessionscontroller      # post /sign_in     def new       user = user.find_by_email(params[:user][:email]) if params[:user]        if user && user.valid_password?(params[:user][:password])         sign_in(:user, user)         current_user.remember_me!         head 200       else         render status: 200, json: {errors: ["incorrect email / username or password."]}.as_json       end     end      # ...    end end 

the above code seems work fine, however, after signing in , visiting /posts route , error telling me "you need sign in or sign before continuing."

the structure of app:

controllers ├── v1 |   ├── users |   |   ├── registrations_controller.rb |   |   ├── sessions_controller.rb |   |   ├── api_controller.rb |   ├── posts_controller.rb application_controller.rb 

in posts controller have set before_action :authenticate_v1_user!. i'm using rails build api , i'm testing above routes sending requests tool called postman. i've tried testing angularjs app (on different subdomain api). why error telling me log in when logged in sending correct credentials /sign_in. there special considerations since api?

edit:

my user.rb file:

class user < activerecord::base   has_many :posts   has_many :comments    # include default devise modules. others available are:   # :confirmable, :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable    validates :email, presence: true, uniqueness: true   validates :password, confirmation: true, presence: true   validates :password_confirmation, presence: true end 

my routes.rb file:

rails.application.routes.draw   devise_for :users, controllers: { sessions: "users/sessions", registrations: "users/registrations" }   devise_scope :user     post "sign_in", to: "v1/users/sessions#new"     delete "sign_out", to: "v1/users/sessions#destroy"     post "register", to: "v1/users/registrations#create"   end    namespace :v1, defaults: {format: 'json'}     devise_for :users, controllers: { sessions: "users/sessions", registrations: "users/registrations" }     # routes posts     'posts(/index)', :to => 'posts#index'     post 'posts/create'     delete 'posts/:id', :to => 'posts#destroy'     'posts/show'     put 'posts/:id', :to => 'posts#update'   end end 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -