From 5384ee9e1ff6ec4f47ab764c97270dc4b282f846 Mon Sep 17 00:00:00 2001 From: Chris Tran Date: Wed, 11 Dec 2024 04:09:05 +0000 Subject: [PATCH] fix: sets create magic link channel for email and phone identifiers --- custom/lib/Auth.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/custom/lib/Auth.php b/custom/lib/Auth.php index 7921b00..f1c0555 100644 --- a/custom/lib/Auth.php +++ b/custom/lib/Auth.php @@ -14,6 +14,7 @@ use OpenAPI\Client\Api\MagicLinksApi; use OpenAPI\Client\Model\CreateMagicLinkRequest; use OpenAPI\Client\Model\MagicLink; +use OpenAPI\Client\Model\MagicLinkChannel; class Auth { @@ -85,25 +86,35 @@ public function createMagicLink( MagicLinkWithEmailArgs|MagicLinkWithPhoneArgs|MagicLinkWithUserArgs $args, MagicLinkOptions|null $options, ): MagicLink { - $payload = new CreateMagicLinkRequest(); - $payload->setType($args->type); - $payload->setSend($args->send); + $identifier = null; + $channel = null; switch ($args) { case $args instanceof MagicLinkWithEmailArgs: - $payload->setEmail($args->email); + $identifier = $args->email; + $channel = MagicLinkChannel::EMAIL; break; case $args instanceof MagicLinkWithPhoneArgs: - $payload->setPhone($args->phone); + $identifier = $args->phone; + $channel = MagicLinkChannel::PHONE; break; case $args instanceof MagicLinkWithUserArgs: - $payload->setUserId($args->userId); - $payload->setChannel($args->channel); + $identifier = $args->userId; + $channel = $args->channel; break; default: throw new InvalidArgumentException("args must contain an email, phone, or userId"); } + $payload = new CreateMagicLinkRequest( + [ + 'identifier' => $identifier, + 'channel' => $channel, + 'type' => $args->type, + 'send' => $args->send, + ] + ); + if ($options) { if ($options->language) { $payload->setLanguage($options->language);