Skip to content

Commit

Permalink
return created otp with response
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed May 2, 2024
1 parent 37fecad commit 4e117a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Http/Controllers/OneTimePinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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());
Expand Down
20 changes: 16 additions & 4 deletions src/Services/OneTimePinService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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')
];
}

/**
Expand Down

0 comments on commit 4e117a1

Please sign in to comment.