Jake Vanderwerf
2026-08-25 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a
inc/rest/routes/MagicLinkRoutes.php
@@ -2,7 +2,7 @@
namespace JVBase\rest\routes;
use JVBase\rest\RestRouteManager;
use JVBase\managers\MagicLinkManager;
use JVBase\managers\MagicLinks;
use WP_REST_Request;
use WP_REST_Response;
use WP_Error;
@@ -110,7 +110,7 @@
         return $this->error('Security verification failed', 'turnstile_failed', 403);
      }
      $email = sanitize_email($request->get_param('email')??$request->get_param('user_email')??'');
      $type = sanitize_text_field($request->get_param('type')) ?? MagicLinkManager::TYPE_LOGIN;
      $type = sanitize_text_field($request->get_param('type')) ?? MagicLinks::TYPE_LOGIN;
      $context = $request->get_param('context') ?? [];
      // Validate email
@@ -123,20 +123,20 @@
      // Check if email exists
      $exists = email_exists($email);
      if ($type === MagicLinkManager::TYPE_LOGIN && !$exists) {
      if ($type === MagicLinks::TYPE_LOGIN && !$exists) {
         return new WP_REST_Response([
            'success' => true,
            'message' => 'Invalid email address'
         ]);
      }
      if ($type === MagicLinkManager::TYPE_SIGNUP && $exists) {
      if ($type === MagicLinks::TYPE_SIGNUP && $exists) {
         // Redirect to login instead
         $type = MagicLinkManager::TYPE_LOGIN;
         $type = MagicLinks::TYPE_LOGIN;
      }
      // Send the magic link
      $result = JVB()->magicLink()?->sendMagicLink($email, $type, $context);
      $result = MagicLinks::getInstance()?->sendMagicLink($email, $type, $context);
      if (is_wp_error($result)) {
         return new WP_REST_Response([
@@ -178,7 +178,7 @@
      $email = sanitize_email($request->get_param('email'));
      // This returns array|WP_Error - check for error first
      $token_data = JVB()->magicLink()?->verifyToken($token, $email);
      $token_data = MagicLinks::getInstance()?->verifyToken($token, $email);
      if (is_wp_error($token_data)) {
         return new WP_REST_Response([