From a9b3b28d001941921aa70d37fdc87c758a163a44 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 05 Jun 2026 16:47:03 +0000
Subject: [PATCH] =Some hefty changes to FeedBlock. Transitioning to loading first page in php to save on extra requests. Got a bit to do yet, but I have to work on Northeh for a bit here.

---
 inc/rest/routes/LoginRoutes.php |   64 +++++++++++++++++--------------
 1 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/inc/rest/routes/LoginRoutes.php b/inc/rest/routes/LoginRoutes.php
index 8ab30ce..2e863ee 100644
--- a/inc/rest/routes/LoginRoutes.php
+++ b/inc/rest/routes/LoginRoutes.php
@@ -1,9 +1,11 @@
 <?php
 namespace JVBase\rest\routes;
 
+use JVBase\managers\Cache;
+use JVBase\registrar\Registrar;
 use JVBase\rest\Rest;
 use JVBase\rest\Route;
-use JVBase\utility\Features;
+use JVBase\base\Site;
 use WP_REST_Request;
 use WP_REST_Response;
 use WP_Error;
@@ -30,7 +32,7 @@
 
 		parent::__construct();
 
-		$this->hasMagicLink = Features::forSite()->has('magicLink');
+		$this->hasMagicLink = Site::has('magicLink');
 	}
 
 	public function registerRoutes(): void
@@ -261,7 +263,7 @@
 		]);
 
 		// Process referral code if provided
-		if (!empty($referral_code) && Features::forSite()->has('referrals')) {
+		if (!empty($referral_code) && Site::has('referrals')) {
 			$this->processReferralCode($user_id, $referral_code);
 		}
 
@@ -630,17 +632,17 @@
 		}
 
 		// Check if role is valid and can register
-		$role_config = JVB_USER[$user_select] ?? null;
+		$registrar = Registrar::getInstance($user_select);
 
-		if (!$role_config) {
+		if (!$registrar) {
 			return new WP_Error('invalid_role', 'Invalid role selected.');
 		}
 
-		if (!($role_config['can_register'] ?? false)) {
+		if (!($registrar->hasFeature('can_register') ?? false)) {
 			return new WP_Error('role_not_allowed', 'This role cannot be selected during registration.');
 		}
 
-		return BASE . $user_select;
+		return $registrar->getBased();
 	}
 
 	/**
@@ -648,7 +650,7 @@
 	 */
 	protected function processReferralCode(int $user_id, string $referral_code): void
 	{
-		if (!Features::forSite()->has('referrals')) {
+		if (!Site::has('referrals')) {
 			return;
 		}
 
@@ -710,41 +712,45 @@
 		}
 	}
 
+	public static function auth():array
+	{
+		return (new self)->buildAuth();
+	}
+
 	protected function buildAuth(?int $user = null): array
 	{
-		if (is_user_logged_in()) {
-			$user = ($user) ?: get_current_user_id();
-			return [
-				'authenticated' => true,
-				'user' => $user,
-				'nonces' => $this->getUserNonces($user)
-			];
-		}
+		$userId = $user ?? (is_user_logged_in() ? get_current_user_id() : 0);
+		$cacheKey = $userId ?: 'guest';
 
-		return [
-			'authenticated' => false,
-			'user' => false,
-			'nonces' => [
-				'wp_rest' => wp_create_nonce('wp_rest')
-			]
-		];
+		return Cache::for('auth', 300)->remember($cacheKey, function() use ($userId) {
+			if ($userId) {
+				return [
+					'authenticated' => true,
+					'user'          => $userId,
+					'nonces'        => $this->getUserNonces($userId),
+				];
+			}
+			return [
+				'authenticated' => false,
+				'user'          => false,
+				'nonces'        => ['wp_rest' => wp_create_nonce('wp_rest')],
+			];
+		});
 	}
 	protected function getUserNonces(int $userID):array {
 		$nonces = [
 			'wp_rest'	=> wp_create_nonce('wp_rest'),
 		];
-		if (Features::forSite()->has('dashboard')) {
+		if (Site::has('dashboard')) {
 			$nonces['dash'] = wp_create_nonce('dash-'.$userID);
 		}
-		if (Features::forSite()->has('favourites')) {
+		if (Site::has('favourites')) {
 			$nonces['favourites'] = wp_create_nonce('favourites-'.$userID);
 		}
-		if (Features::anyContentHas('karma') ||
-			Features::anyTaxonomyHas('karma') ||
-			Features::anyUserHas('karma')) {
+		if (!empty(Registrar::getFeatured('karma'))) {
 			$nonces['votes'] = wp_create_nonce('votes-'.$userID);
 		}
-		if (Features::forSite()->has('notifications')) {
+		if (Site::has('notifications')) {
 			$nonces['notifications'] = wp_create_nonce('notifications-'.$userID);
 		}
 		return $nonces;

--
Gitblit v1.10.0