title: Laravel passport & Vue login
body: <p>I've made login function in laravel with passport api and I'm getting status 200, <strong>the issue is</strong> that i don't know how to login the user and redirect to homepage after this successful request <strong>(I'm using vuejs component)</strong>.</p>
  
  <h1>Code</h1>
  
  <p><code>controller</code></p>
  
  <pre><code>public function login(Request $request)
      {
          $credentials = [
              'email' =&gt; $request-&gt;email,
              'password' =&gt; $request-&gt;password
          ];
  
          if (Auth::attempt($credentials)) {
              // $token = auth()-&gt;user()-&gt;createToken('AppName')-&gt;accessToken;
              // $success['token'] =  $token;
              // $success['name'] =  auth()-&gt;user()-&gt;name;
              // $success['id'] =  auth()-&gt;user()-&gt;id;
            $user = Auth::user();
              $success['token'] = $user-&gt;createToken('AppName')-&gt;accessToken;
              $success['user'] = $user;
              return response()-&gt;json(['success'=&gt;$success], 200);
          } else {
              return response()-&gt;json(['error' =&gt; 'UnAuthorised'], 401);
          }
      }
  </code></pre>
  
  <p><code>component script</code></p>
  
  <pre><code>&lt;script&gt;
      import {login} from '../../helpers/Auth';
  
      export default {
          name: "login",
          data() {
              return {
                  form: {
                      email: '',
                      password: ''
                  },
                  error: null
              };
          },
          methods: {
              authenticate() {
                  this.$store.dispatch('login');
  
                  axios.post('/api/auth/login', this.form)
                  .then((response) =&gt; {
                      setAuthorization(response.data.access_token);
                      res(response.data);
                  })
                  .catch((err) =&gt;{
                      rej("Wrong email or password");
                  })
  
              }
          },
          computed: {
              authError() {
                  return this.$store.getters.authError;
              }
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p><code>Auth.js (imported in script above)</code></p>
  
  <pre><code>import { setAuthorization } from "./general";
  
  export function login(credentials) {
      return new Promise((res, rej) =&gt; {
          axios.post('/api/auth/login', credentials)
              .then((response) =&gt; {
                  setAuthorization(response.data.access_token);
                  res(response.data);
              })
              .catch((err) =&gt;{
                  rej("Wrong email or password");
              })
      })
  }
  </code></pre>
  
  <p><code>general.js (imported in script above)</code></p>
  
  <pre><code>export function setAuthorization(token) {
      axios.defaults.headers.common["Authorization"] = `Bearer ${token}`
  }
  </code></pre>
  
  <h1>Question</h1>
  
  <ol>
  <li>How can I login my user after successful request?</li>
  </ol>
  
  <p>...........................................................................................................................................................</p>