DevMarketer / multiauth_tutorial

156 stars 83 forks source link

Admin login errors not showing #14

Open knnhcn opened 6 years ago

knnhcn commented 6 years ago

I did all the tutorials and it works fine. But I have the problem, that admin login form does not show errors when for example entering a wrong e-mail addresse. The user login form shows the errors, but the admin login not.

sayhicoelho commented 6 years ago

Please post your Admin/LoginController's code. I'll try to help you.

knnhcn commented 6 years ago

Hi there, thank you for your offer. Here is my AdminLoginController:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class AdminLoginController extends Controller
{
    public function __construct()
    {
        $this->middleware('guest:admin', ['except' => ['logout']]);
    }

    public function showLoginForm()
    {
        return view('auth.admin-login');
    }

    public function login(Request $request)
    {
        // Validate the form data
        $this->validate($request, [
            'email'   => 'required|email',
            'password' => 'required|min:6'
        ]);
        // Attempt to log the user in
        if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
            // if successful, then redirect to their intended location
            return redirect()->intended(route('admin.dashboard'));
        }
        // if unsuccessful, then redirect back to the login with the form data
        return redirect()->back()->withInput($request->only('email', 'remember'));
    }

    public function logout()
    {
        Auth::guard('admin')->logout();
        return redirect('/');
    }
}
sayhicoelho commented 6 years ago

It seems fine.

What can be causing the bug:

You should paste the admin login view here.

Furthermore, try to go into this step by step created by me: https://medium.com/@renandiett/laravel-5-4-trabalhando-com-autentica%C3%A7%C3%B5es-independentes-sem-packages-adicionais-6e50c11a0b79

If you do not understand Portuguese, I suggest you to use a translator like Google.

tulioribeiro commented 5 years ago

I had the same issue and it's because of this line: return redirect()->back()->withInput($request->only('email', 'remember'));

To resolve this I followed the same paradigm of the AuthenticatesUsers trait:

protected function sendFailedLoginResponse(Request $request)
{
    throw ValidationException::withMessages([
        $this->username() => [trans('auth.failed')],
    ]);
}