From c6063aa9806471639e1440f2c21134e76288b4d9 Mon Sep 17 00:00:00 2001 From: mohanmd Date: Tue, 26 May 2026 18:07:37 +0530 Subject: [PATCH] changes --- .../Api/EmployerAuthController.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/EmployerAuthController.php b/app/Http/Controllers/Api/EmployerAuthController.php index 3602f33..c83faea 100644 --- a/app/Http/Controllers/Api/EmployerAuthController.php +++ b/app/Http/Controllers/Api/EmployerAuthController.php @@ -115,7 +115,7 @@ public function register(Request $request) \Illuminate\Support\Facades\Cache::put('employer_otp_' . $request->email, [ 'code' => $otp, - 'expires_at' => now()->addMinutes(10) + 'expires_at' => now()->addMinutes(10)->timestamp ], 600); // Create inactive User @@ -196,10 +196,25 @@ public function verify(Request $request) 'errors' => $validator->errors() ], 422); } - $cachedData = \Illuminate\Support\Facades\Cache::get('employer_otp_' . $request->email); - if (!$cachedData || $cachedData['code'] !== $request->otp || now()->gt($cachedData['expires_at'])) { + if (!$cachedData || !isset($cachedData['code']) || !isset($cachedData['expires_at'])) { + return response()->json([ + 'success' => false, + 'message' => 'Invalid or expired verification code.' + ], 400); + } + + // Handle any dirty/legacy cache objects gracefully + if (is_object($cachedData['expires_at']) || $cachedData['expires_at'] instanceof \__PHP_Incomplete_Class) { + \Illuminate\Support\Facades\Cache::forget('employer_otp_' . $request->email); + return response()->json([ + 'success' => false, + 'message' => 'Session expired. Please request a new verification code.' + ], 400); + } + + if ($cachedData['code'] !== $request->otp || now()->timestamp > $cachedData['expires_at']) { return response()->json([ 'success' => false, 'message' => 'Invalid or expired verification code.'