Ad

Login Page Redirect To Blank Page Afer Authentication In Laravel 6

- 1 answer

my login page redirect me to blank page with url:http://127.0.0.1:8000/login instead of the dashboard. this is my loginController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use App\Http\Requests\LoginRequest;

class LoginController extends Controller
{
    public function show()
    {
        return view('auth/login');
    }

    public function authenticate(LoginRequest $requestFields)
    {

        $attributes = $requestFields->only(['username', 'password']);

        if (Auth::attempt($attributes)) {

            return redirect()->route('dashboard');

        }
    }

    public function logout()
    {
        Session::flush();
        Auth::logout();
        return back();
    }

}

loginRequest class

class LoginRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */

    public function authorize()
    {
        return true;  // Set this to "true" else Unauthorized error will be thrown
    }

    public function rules()
    {
        return [
            'username'     => ['required', 'string'],
            'password'  => ['required', 'string', 'min:8'],
        ];
    }
}

web.php

// Register & Login User
Route::post('/login', '[email protected]');
Route::post('/register', '[email protected]');


// Protected Routes - allows only logged in users
Route::middleware('auth')->group(function () {
    Route::get('/dashboard', '[email protected]')->name('dashboard');
    Route::post('/logout', '[email protected]');
});

I expected redirect to dashboard page after login using the username and password,I tried changing the route in RedirectIfAuthenticated.php but it did not work.

Ad

Answer

the issue was I didn't hash my password properly in the registerController hence I couldn't authenticate user that log in.

Ad
source: stackoverflow.com
Ad