Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with jetstream inertia #354

Closed
makz27 opened this issue Sep 14, 2021 · 2 comments
Closed

Issue with jetstream inertia #354

makz27 opened this issue Sep 14, 2021 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@makz27
Copy link

makz27 commented Sep 14, 2021

Environment:

  • LDAP Server Type: Samba 4 ActiveDirectory
  • LdapRecord-Laravel Major Version: v2
  • PHP Version: 7.4

Describe the bug:

I've followed the docs on a blank project, using jetstream inertia stack.
The login is working fine but when i try to reach a random page after login, i get this error

Call to undefined method LdapRecord\Query\Model\ActiveDirectoryBuilder::toArray()

In the stack trace, i see the toArray() function is called in vendor/laravel/jetstream/src/Http/Middleware/ShareInertiaData.php:48

return array_merge($request->user()->toArray(), array_filter([

This is my auth.php

<?php

return [
    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'ldap',
            'model' => LdapRecord\Models\ActiveDirectory\User::class,
            'rules' => [],
        ],
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
            'throttle' => 60,
        ],
    ],

    'password_timeout' => 10800,

];

AuthServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Fortify\Fortify;
use Illuminate\Support\Facades\Auth;

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        // 'App\Models\Model' => 'App\Policies\ModelPolicy',
    ];

    public function boot()
    {
        $this->registerPolicies();

        Fortify::authenticateUsing(function ($request) {
            $validated = Auth::validate([
                'samaccountname' => $request->username,
                'password' => $request->password
            ]);

            return $validated ? Auth::getLastAttempted() : null;
        });
    }
}

@makz27 makz27 added the bug Something isn't working label Sep 14, 2021
@stevebauman stevebauman added enhancement New feature or request question Further information is requested and removed bug Something isn't working labels Sep 14, 2021
@stevebauman
Copy link
Member

Hi @makz27,

LdapRecord models do not have the toArray() method. You will instead have to use:

$request->user()->attributesToArray();

https://ldaprecord.com/docs/core/v2/model-api/#attributestoarray

Though to maintain parity with Laravel's Eloquent, I'm going to patch this method in so developers don't need to think about it 👍

@stevebauman
Copy link
Member

I've just released v2.7.0 with this patch.

Please run composer update and then you'll be all set. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants