I have an application with subdomains. When a User logs in at the root domain. I want to redirect him/her to his/her firms subdomain. I am useing devise.
This is what I have so far
def create
subdomain = request.subdomain
user = User.find_by_email(params[:user][:email])
if subdomain.present?
resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
redirect_to statistics_url
else
redirect_to sign_in_at_subdomain_url(:subdomain => user.firm.subdomain), :params => params
end
end
def sign_in_at_subdomain
resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
redirect_to statistics_url
end
When the user login trough the login form, params gets sent to the create action, that devise use for authentication. As you see in my code, when a subdomain is present the login works great, but when it is not present I want to do a redirect to the subdomain and sign_in_at_subdomain.
How can I pass the parmas form the form trough the create action to the sign_in_at_subdomain action?
You can use
after_sign_in_path_forto sign_out the user from the root romain and sign him in to the subdomain he belongs to. The following is from the example Rails 3 app with basecamp like subdomains and authentication (using Devise).