'Managing redirects to a subdomain after authentication in a React/Rails application using React Router
I have a React single page application using React Router that hooks into a Rails 5 API. The Rails application uses devise_token_auth for authentication. I've successfully created an authentication process that stores the user state in a Redux store on the client side.
Each user of the application belongs to a company. Each company has its own unique subdomain (e.g., companya.foo.com, companyb.foo.com). A user should be redirected to their company subdomain after signing in from foo.com. All requests for an authenticated user should keep them on their own subdomain. Users should be redirected back to foo.com when they sign out.
I read that this is impossible with React Router and the browser API but there has to be a way to achieve this. I also saw some .htaccess suggestions but I am unfamiliar with this approach and I'm not sure if this will handle dynamic redirects.
What is the most intuitive approach to solve this problem?
Solution 1:[1]
You would need to redirect to the subdomain and pass the authentication token in the params to keep the user logged in
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dorian |
