have a look into manually authenticating users https://laravel.com/docs/10.x/authentication#authenticating-users
Aug 24, 2023
4
Level 1
Authenticate users by consuming an external JSON API endpoint from server side.
Incoming credentials must be validated on the server side by consuming the API. I already get a successful response but It does not redirect me to the index or I got successful response but I do not get authenticated so it redirects me back to the login page because I use middleware('auth') in the index page. This is my first time working with api so I am not sure what to do. Do I still need to use database here?
AuthController:
public function signin(Request $request)
{
$request->validate([
'username' => 'required',
'password' => 'required',
]);
$credentials = $request->only('username', 'password');
$response = Http::post('url cannot be displayed', $credentials);
if ($response->successful()) {
return redirect()->route('index');
} else {
return back()->with('error', 'Invalid username or password');
}
}
web.php
Route::get('/', [IndexController::class, 'index'])->middleware('auth')->name('index');
Route::get('/account/login', [AuthController::class, 'login'])->name('login');
Route::post('/account/login', [AuthController::class, 'signin'])->name('signin');
Please or to participate in this conversation.