title: Laravel 4 Authentication not working with Subdomains
body: <p>In my L4 App i use subdomains for my routing to different stuff.</p>
  
  <pre><code>accounts.domain.com = where alle the Authentication stuff happens
  dashboard.domain.com = The main frontpage for authenticated users
  community.domain.com = Community stuff for authenticated users.
  </code></pre>
  
  <p>If someone visits community.domain.com/forum and is not autenticated he should be send to accounts.domain.com, login and then get redirected back to the Forum.</p>
  
  <p>But now i have 2 problems.
  1 and major problem: afer the login the user is only autenticated for the domain: accounts.domain.com
  for all other domains he gets redirected to the login.
  If a user is autenticated and trys to access dashboard.domain.com he gets redirected to the login page.</p>
  
  <p>and the 2. problem is the redirect after the login.
  Atm i just have a static redirect after the login, doesn't matter where the user was coming from. How can i change it so he get redirected back to the page he tried to visited as unauthenticated user before?
  My routes file:</p>
  
  <pre><code>Route::get('login', function()
  {
      return Redirect::action('AccountsController@getLogin');
  });
  
  Route::group(array('domain' =&gt; 'accounts.domain.com'), function()
  {
      Route::get('/', function()
      {
          return Redirect::action('AccountsController@getLogin');
      });
  
      Route::get('users/sing_in', array('as' =&gt; 'login', 'uses' =&gt; 'AccountsController@getLogin'));
      Route::post('users/sing_in', array('as' =&gt; 'login', 'uses' =&gt; 'AccountsController@doLogin'));
      Route::get('users/sing_out', array('as' =&gt; 'logout', 'uses' =&gt; 'AccountsController@doLogout'));
  
  
      Route::group(array('before' =&gt; 'auth'), function() {
          Route::get('users/profile', array('as' =&gt; 'profile', 'uses' =&gt; 'AccountsController@getProfile'));
      });
  
  });
  
  
  Route::group(array('domain' =&gt; 'dashboard.domain.com'), function()
  {
      Route::group(array('before' =&gt; 'auth'), function() {
          Route::get('/', array('as' =&gt; 'dashhome', 'uses' =&gt; 'DashboardController@getIndex')); //If someone tries to access this, he get redirected to the login page, even if he just authenticated himself
      });
  });
  </code></pre>
  
  <p>And my Login Controller:</p>
  
  <pre><code>public function getLogin()
  {
      if (Auth::check()) {
          return Redirect::action('AccountsController@getProfile'); 
      } else {
          return View::make('login.index');
      }
  }
  public function doLogin()
  {
      $rules = array(
          'email'    =&gt; 'required|email',
          'password' =&gt; 'required|min:3'
      );
  
      $validator = Validator::make(Input::all(), $rules);
  
      if ($validator-&gt;fails()) {
          return Redirect::route('login')
              -&gt;withErrors($validator)
              -&gt;withInput(Input::except('password'));
      } else {
          $userdata = array(
              'email'     =&gt; Input::get('email'),
              'password'  =&gt; Input::get('password')
          );
          if (Auth::attempt($userdata)) {
              return Redirect::action('AccountsController@getProfile');
          } else {
              return Redirect::route('login')-&gt;withErros('Wrong E-mail address or Password');
          }
      }
  }
  public function doLogout()
  {
      Auth::logout(); // log the user out of our application
      return Redirect::route('login'); // redirect the user to the login screen
  }
  </code></pre>
  
  <p>Thanks for any help.</p>