title: Laravel JWT Multi-Page Structure
body: <p>Its to my knowledge that a JWT based authorization system is usually reserved for SPA'S ( you know, one view, one React/Angular/Vue app, with one bloated app.js file), however I'm attempting to utilize the magic of JWT with a slightly separate structured application.</p>
  
  <p><strong>Structure</strong></p>
  
  <p>Rather than serving up one <code>blade.php</code> view from my <code>Laravel</code> app that garners one <code>Vue</code> app and instance, I'm attempting to serve up TWO separate <code>blade.php</code> views, that each operate as their own separate <code>Vue SPA</code><strong>:</strong> one for the exterior of the application (pre-auth) and another for the interior of the app (post-auth). </p>
  
  <p><strong>Current State of App</strong></p>
  
  <p>To power my app's authentication system, I've utilized <a href="https://github.com/tymondesigns/jwt-auth" rel="noreferrer">Tymon's jwt-auth</a> lib ( a beautiful lib btw ) and tie everything together on the front with (as previously stated) <code>Vue/Vuex</code>. Everything works as expected, in my <code>Register</code> and <code>Login</code> components I'm able to hit my api, get a JWT in response, store it locally then annex said token into my <a href="https://github.com/tymondesigns/jwt-auth" rel="noreferrer">Axios</a> headers allowing all subsequent requests to harbor this token.</p>
  
  <p><strong>Dilemma</strong></p>
  
  <p>Now I'm at a crossroads. The post-auth route/view that I want to serve up is protected by a custom <code>JWT</code> middleware that redirects if a valid token is not presented:</p>
  
  <pre><code>Route::get('/home', 'Auth\HomeController@home')-&gt;middleware('jwt');
  </code></pre>
  
  <p><em>middleware</em></p>
  
  <pre><code>class JWT
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
          JWTAuth::parseToken()-&gt;authenticate();
  
          return $next($request);
      }
  }
  </code></pre>
  
  <p>and my pre-auth view and all its routes are protected by Laravel's native guest <code>RedirectIfAuthenticated</code> middleware, which is Guarded by JWT now:</p>
  
  <pre><code>class RedirectIfAuthenticated
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @param  string|null  $guard
       * @return mixed
       */
      public function handle($request, Closure $next, $guard = null)
      {
          if (Auth::guard($guard)-&gt;check()) {
              return redirect('/home');
          }
  
          return $next($request);
      }
  }
  </code></pre>
  
  <p><strong>Questions</strong></p>
  
  <p>So this begs down to the following questions:</p>
  
  <p>1) after a successful register/login on the front-end and a JWT is generated, stored locally and in Axios headers, How do I then redirect to my post-auth route with this valid token available?</p>
  
  <p>2) How do I then make sure that Valid JWT persist and is present when the guest routes are hit to successfully redirect back to my post-auth route?</p>
  
  <p><strong>I'd prefer to keep all redirects and persistance checks on the backend if feasible</strong> </p>