apiService = $apiService; } public function login(Request $request) { $credentials = $request->validate([ 'email' => 'required|email', 'password' => 'required', ]); try { $response = $this->apiService->post('/auth/login', $credentials); if ($response->successful()) { $data = $response->json(); session(['api_token' => $data['token']]); return redirect()->intended('/dashboard'); } return back()->withErrors([ 'email' => 'The provided credentials do not match our records.', ]); } catch (\Exception $e) { return back()->withErrors([ 'error' => 'Unable to connect to the authentication service.', ]); } } public function logout() { try { $this->apiService->post('/auth/logout'); } catch (\Exception $e) { // Log the error but proceed with local logout } Session::forget('api_token'); return redirect('/login'); } }