Skip to content

Commit feb1260

Browse files
committed
return early if not json
Moves longer logic outside the if block, removes the nested if
1 parent 18b5165 commit feb1260

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/Http/Responses/PasskeyRegistrationResponse.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public function withPasskey(Passkey $passkey): static
3333
*/
3434
public function toResponse($request)
3535
{
36-
if ($request->wantsJson()) {
37-
$data = ['status' => 'passkey-registered'];
36+
if (! $request->wantsJson()) {
37+
return back()->with('status', 'passkey-registered');
38+
}
3839

39-
if ($this->passkey instanceof \Laravel\Passkeys\Passkey) {
40-
$data['id'] = (string) $this->passkey->id;
41-
$data['name'] = $this->passkey->name;
42-
}
40+
$data = ['status' => 'passkey-registered'];
4341

44-
return new JsonResponse($data, 200);
42+
if ($this->passkey instanceof \Laravel\Passkeys\Passkey) {
43+
$data['id'] = (string) $this->passkey->id;
44+
$data['name'] = $this->passkey->name;
4545
}
4646

47-
return back()->with('status', 'passkey-registered');
47+
return new JsonResponse($data, 200);
4848
}
4949
}

0 commit comments

Comments
 (0)