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 AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;
use IlluminateSupportFacadesSession;
use AppHttpRequestsLoginRequest;
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', 'LoginController@authenticate');
Route::post('/register', 'RegistrationController@register');
// Protected Routes - allows only logged in users
Route::middleware('auth')->group(function () {
Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
Route::post('/logout', 'LoginController@logout');
});
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.
Advertisement
Answer
the issue was I didn’t hash my password properly in the registerController hence I couldn’t authenticate user that log in.