Laravel 5.2.14 with Duxet/RethinkDB Authentication Redirect User Seen as Guest in Home Route

时间:2016-02-12 19:50:08

标签: laravel laravel-5 rethinkdb laravel-5.2

Using a clean install of Laravel 5.2.14, adding the migration and seed files, adding the auth scaffolding using artisan make:auth, and running this using MySQL, and finally logging into the dashboard works as usual, but when I add Duxet/RethinkDB; update the migration, seed, and User model; and attempt to login it no longer redirects to /home, but back to /login. You can see in the network tab of Chrome that /login gets a 302 error, /home gets a 302 error, and it returns to /login indicating an issue in the middleware of the home route.

login   302 text/html
home    302 text/html
login   200 document

No exception is thrown or error logged, but stubbing through the Auth middleware using Monolog (/app/Http/Middleware/Authenticate). The statement Auth::guard($guard)->guest() always returns 1 indicating that the user is a guest causing the redirect, but it appears to authenticate the user from stubbing through AuthController's AuthenticatesAndRegistersUsers child trait AuthenticatesUsers::login. So clicking home in the navigation just redirects to the login since the home middleware indicates the user is a guest.

public function login(Request $request)
{
    $this->validateLogin($request);

    ...

    if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {

        Log::info('Successful Login!'); // Always gets here

        return $this->handleUserWasAuthenticated($request, $throttles);
    }

    Log::info('Failed Login!'); // Never gets here

    ...

If I revert to the previous commit that uses just MySQL this all works, and the user is redirected to the dashboard. I've been stubbing my way through the web middleware group, auth middleware, and AuthController traits; trying to figure this out with no luck.

Has anyone run into this and can point at a potential solution?

1 个答案:

答案 0 :(得分:0)

经过几个小时的尝试,通过删除和削减代码来解决这个问题,我最终注意到一个用户的ID,对于我播种的用户数量来说太大了,结果证明是整数截断的UUID的一部分。

问题产生于如何实现Duxet / RethinkDB包,它不使用Laravel在为具有自动递增ID的典型迁移构建语句时实现的Blueprint方法:

use duxet\Rethinkdb\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

    public function up()
    {
        Schema::create('users', function(Blueprint $table) {
            $table->increments('id'); // Won't be an auto-incrementing unsigned integer
            ...
        });
    }

    ...
}

和种子:

use Illuminate\Database\Seeder;

class UserTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Developer accounts
        factory(App\User::class, 'admin', 1)->create([
            'username' => 'test',
            'email' => 'test@test.com'
        ]);
}

注意:我想注意Duxet / RethinkDB软件包没有任何问题。在尝试在Laravel中实现它时,这是需要注意的事项。

Duxet / RethinkDB使用简洁的方法来创建表,而无需为增量等方法调用Laravel的API,这些方法处理将无符号整数分配给ID列。 ReQL语句r.db('app').table('users')结果表明为ID列分配了一个UUID,它通常是Laravel自动递增的无符号整数。

{
"created_at": Fri Feb 12 2016 10:04:22 GMT+00:00 ,
"email": test@test.com, »
"id":  "8bbc1c35-6be5-4b1f-87de-75eba1c459eb" ,
"password":  "$2y$10$2f7QjuBCjEMr3R01ZNlwI.ft8v8FYs8IHRQzPI1lKdojIXtK7b9wO" ,
"role":  "admin" ,
"updated_at": Fri Feb 12 2016 10:04:22 GMT+00:00 ,
"username":  "test"
}

为了克服set increment to false,这将阻止Laravel将UUID转换为PHP整数数据类型,从而截断UUID。我已经提交了一个PR来对Duxet / RethinkDB软件包进行一些更改,以防止其他人自己发现这个。