diff --git a/src/Http/Controllers/OneTimePinController.php b/src/Http/Controllers/OneTimePinController.php index 26cfd68..b1c564e 100644 --- a/src/Http/Controllers/OneTimePinController.php +++ b/src/Http/Controllers/OneTimePinController.php @@ -30,7 +30,7 @@ public function request(CreateOneTimePinRequest $request): JsonResponse $targetField = $request->has('mobile') ? 'mobile' : ( - $request->has('email') + $request->has('email') ? 'email' : ($request->has('user') ? 'user' : null) ); @@ -49,7 +49,9 @@ public function request(CreateOneTimePinRequest $request): JsonResponse throw new Exception($response['message']); } - return $this->success($response['message']); + unset($response['status']); + + return $this->success($response); } catch (Exception $exception) { return $this->failed($exception->getMessage()); diff --git a/src/Services/OneTimePinService.php b/src/Services/OneTimePinService.php index d170ca1..71d9dee 100644 --- a/src/Services/OneTimePinService.php +++ b/src/Services/OneTimePinService.php @@ -31,7 +31,7 @@ public function __construct(private readonly OneTimePinRepository $oneTimePinRep * @return array * @throws Exception */ - public function create(string $authField) + public function create(string $authField): array { $this->delete($authField); @@ -48,14 +48,26 @@ public function create(string $authField) 'value' => $token ]; - if ($this->oneTimePinRepository->create($authField, $token)) { + if ($otp = $this->oneTimePinRepository->create($authField, $token)) { Notification::route($channel, $authField)->notify(new OTPNotification($notification_data)); - return ['status' => true, 'message' => __('auth::messages.verify.' . $this->otpMethod, ['channel' => $channel])]; + $response = [ + 'status' => true, + 'message' => __('auth::messages.verify.' . $this->otpMethod, ['channel' => $channel]), + ]; + + if (!app()->isProduction()) { + $response['otp'] = $otp->token ?? null; + } + + return $response; } - return ['status' => false, 'message' => __('auth::messages.verify.failed')]; + return [ + 'status' => false, + 'message' => __('auth::messages.verify.failed') + ]; } /**