I added to 'create' the next lines:
in the beginning, I wrote:
resource = warden.authenticate!(:scope => resource_name)
and then I wrote in the end of the 'create' function:
sign_in(resource_name, resource)
if current_user.role_ids == [2]
respond_with resource, :location => workers_path
else
respond_with resource, :location => tasksadmins_path
end
so my create looks so:
class UserSessionsController < Devise::SessionsController
include ApplicationHelper
def create
resource = warden.authenticate!(:scope => resource_name)
require "uri"
require "net/http"
## get the user id from the database
user_id = session['warden.user.user.key'][1][0];
## get the row by id
user = User.find(user_id)
# ============================
# Ensure that a user exists
# ============================
code, body = http_request(Net::HTTP::Put.new("/api/v1/users/external/#{user_id}"), email: user.email);
if code != 200
Rails.logger.error("Unable to register user #{current_user.email} at Licensario");
end
sign_in(resource_name, resource)
if current_user.role_ids == [2]
respond_with resource, :location => workers_path
else
respond_with resource, :location => tasksadmins_path
end
end
end