Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:20:35+00:00 2026-05-30T15:20:35+00:00

I have an application with subdomains. When a User logs in at the root

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:20:37+00:00Added an answer on May 30, 2026 at 3:20 pm

    You can use after_sign_in_path_for to 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).

    def after_sign_in_path_for(resource_or_scope)
      scope = Devise::Mapping.find_scope!(resource_or_scope)
      subdomain_name = current_user.subdomain.name
      if current_subdomain.nil? 
        # logout of root domain and login by token to subdomain
        token =  Devise.friendly_token
        current_user.loginable_token = token
        current_user.save
        sign_out(current_user)
        flash[:notice] = nil
        home_path = valid_user_url(token, :subdomain => subdomain_name)
        return home_path 
      else
        if subdomain_name != current_subdomain.name 
          # user not part of current_subdomain
          sign_out(current_user)
          flash[:notice] = nil
          flash[:alert] = "Sorry, invalid user or password for subdomain"
        end
      end
      super
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a page where the user enters his credentials. The user is then
I am migrating my application which provides a subsite for each user from domain.com/~user
In myapp/config/initializers/session_store.rb , I have the following: Myapp::Application.config.session_store :cookie_store, :key => '_myapp_session', :domain =>
I've written an application that uses a subdomain per user account to segregate environments.
I'm trying to set up a subdomain for my application because I don't want
We are releasing a paid web application. We have Google Analytics and want to
I have an application where, in the course of using the application, a user
I have a GAE application that is mapped to a subdomain on a custom
I have application which needs to use a dll (also written by me) which
I have application that makes different queries with different results so the caching in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.