Skip to content

Commit 482154a

Browse files
committed
fix: login command
1 parent ff32c8c commit 482154a

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎app/Commands/LoginCommand.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ class LoginCommand extends Command
2222

2323
public function handle()
2424
{
25+
// New token validation flow
26+
if ($tokenOption = $this->option('token')) {
27+
$connector = Helpers::getApiConnector($tokenOption);
28+
29+
try {
30+
$tokenVerify = $connector->send(new CurrentToken);
31+
$tokenVerify->throw();
32+
33+
$userResponse = $connector->send(new CurrentAuthenticated);
34+
$userResponse->throw();
35+
36+
$user = $userResponse->json('data');
37+
Config::set('api.token', $tokenOption);
38+
$this->info('Successfully logged in with token. User: '.$user['name']);
39+
40+
return;
41+
} catch (Exception $e) {
42+
$this->error('Invalid token: '.$e->getMessage());
43+
44+
return;
45+
}
46+
}
47+
48+
// Existing email/password flow
2549
$token = Helpers::getApiToken();
2650
$connector = Helpers::getApiConnector($token ?: '');
2751

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo