[Vuejs]-Attempt to read property "status" on null

0👍

You can check if the $customer variable is null before accessing its status property.

if (!$customer || $customer->status !== CustomerStatus::Active->value) { 
    // handle disabled account
}

-2👍

public function authenticate()
{
    $this->ensureIsNotRateLimited();
    if (!Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
        RateLimiter::hit($this->throttleKey());
        throw ValidationException::withMessages([
            'email' => trans('auth.failed'),
        ]);
    }

    $user = $this->user();
    $customer = $user->customer;

    if ($customer->status !== CustomerStatus::Active->value && $customer->status != null) {
        /*the problem is here*/
        Auth::guard('web')->logout();

        $this->session()->invalidate();
        $this->session()->regenerateToken();
        throw ValidationException::withMessages([
           'email' => 'Your account has been disabled',
        ]);
    }

    RateLimiter::clear($this->throttleKey());
}

Leave a comment