Ad

Why My Laravel Passport Stopped Working When Migrated To Vagrant From Build-in Server?

So I had to implement facebook login, which requires https connection, before I was using php artisan serve, but it only allows http, now I decided to migrate whole project to vagrant. Everything works fine but passport.

I checked and found that theese two lines are causing internal error 500

auth()->attempt($loginData, true);

auth()->user()->createToken('authToken')->accessToken;

when removed, I get no error. My whole login function look like this:

    public function login(Request $request)
    {
        $loginData = $request->validate([
            'name' => 'required',
            'password' => 'required'
        ]);

       $a = auth()->attempt($loginData, true);
        if(!$a) {
            return response(['message'=>'Invalid credentials', 'auth' => false]);
        }
        $accessToken = auth()->user()->createToken('authToken')->accessToken;
        return response(['user' => auth()->user(), 'access_token' => $accessToken, 'auth' => true, "attempt" => $a, "auth()" => auth()]);
    }

In addition, I've created users via tinker, tokens and users were stored.

here is my db data

mysql> select * from users;
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
| id | name  | password                                                     | remember_token | created_at          | updated_at          |
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
|  1 | admin | $2y$10$V8fM6Vvc7xOJxN/LPyImUeQNzG9/k3tSsaF8qf1NsxrzK9B3VPmsa | NULL           | 2019-08-26 15:22:02 | 2019-08-26 15:22:02 |
|  2 | demis | $2y$10$oRvcL0ZC2NQuGXE446GhfO1KBcAw3h8d/TGQmODL/AFHnat1I.Yvq | NULL           | 2019-08-26 15:45:27 | 2019-08-26 15:45:27 |
+----+-------+--------------------------------------------------------------+----------------+---------------------+---------------------+
2 rows in set (0.00 sec)

mysql> select * from oauth_access_tokens;
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
| id                                                                               | user_id | client_id | name      | scopes | revoked | created_at          | updated_at          | expires_at          |
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+
| 2e82923d6fdc1cc98580b683952b7b96d555e67d6b7e06b8080f8a55227b6c1d7a755fc21b570941 |    NULL |         1 | authToken | []     |       0 | 2019-08-26 15:21:52 | 2019-08-26 15:21:52 | 2020-08-26 15:21:52 |
| 610f8fd1f2212ab257810de88605bff4e419f26477bcf63f8dfe20018d9bcf74797bb9c817d6450a |    NULL |         1 | authToken | []     |       0 | 2019-08-26 15:45:19 | 2019-08-26 15:45:19 | 2020-08-26 15:45:19 |
+----------------------------------------------------------------------------------+---------+-----------+-----------+--------+---------+---------------------+---------------------+---------------------+

What's wrong, Why I can't login, maybe there's something wrong with configuration?

Ad

Answer

Run php artisan passport:install on the new server.

Ad
source: stackoverflow.com
Ad