title: Call to undefined method Laravel\Socialite\Two\User::createToken()
body: <p>In a laravel 5.8 API project, I want users to login via their social accounts. So far I have been able to use Socialite to retrieve user info from the provider and use it to create a new user record. But when I try to have the user log in again, it throws up the following error</p>
  
  <blockquote>
    <p>Call to undefined method Laravel\Socialite\Two\User::createToken()</p>
  </blockquote>
  
  <p>Here's the code I am working with</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\User;
  use Socialite;
  use App\SocialAccount;
  use App\Http\Resources\UserResource;
  
  class SocialAuthController extends Controller
  {
      ...
  
      public function handleProviderCallback($provider)
      {
          $socialUser = Socialite::driver($provider)-&gt;stateless()-&gt;user();
  
          $userSocialAccount = SocialAccount::where('provider_id', $socialUser-&gt;id)-&gt;where('provider_name', $provider)-&gt;first();
  
          /*
           if account exist, return the social account user
           else create the user account, then return the new user
          */
          if ($userSocialAccount) {
  
              // generate access token for use
              $token = $socialUser-&gt;createToken('********')-&gt;accessToken;
  
              // return access token &amp; user data
              return response()-&gt;json([
                  'token' =&gt; $token,
                  'user'  =&gt; (new UserResource($userSocialAccount))
              ]);
  
          } else {
  
              $user = User::create([
                  'firstname'            =&gt; $socialUser-&gt;name,
                  'lastname'             =&gt; $socialUser-&gt;name,
                  'username'             =&gt; $socialUser-&gt;email,
                  'email_verified_at'    =&gt; now()
              ]);
  
              if ($user) {
  
                  SocialAccount::create([
                      'provider_id'   =&gt; $socialUser-&gt;id,
                      'provider_name' =&gt; $provider,
                      'user_id'       =&gt; $user-&gt;id
                  ]);
              }
  
              // assign passport token to user
              $token = $user-&gt;createToken('********')-&gt;accessToken;
  
              return response()-&gt;json(['token' =&gt; $token, 'user' =&gt; new UserResource($user)]);
  
          }
      }
  }
  </code></pre>
  
  <p>I haven't been able to spot the reason why I am getting the error when the user attempts a second login but there is no error if it's the first time the user logs in with a social account.</p>
  
  <p>Why does it complain about <code>Laravel\Socialite\Two\User::createToken()</code> method? If I try adding this line <code>use Laravel\Socialite\Two\User</code> vscode intelephsense flags it as a duplicate of <code>App\User</code> so what is really going on in my code?</p>