diff --git a/frontend-web-free/src/api/krowSDK.js b/frontend-web-free/src/api/krowSDK.js index d6e81185..4f9c2f0b 100644 --- a/frontend-web-free/src/api/krowSDK.js +++ b/frontend-web-free/src/api/krowSDK.js @@ -4,6 +4,8 @@ import { signOut } from 'firebase/auth'; import * as dcSdk from '@dataconnect/generated'; // listEvents, createEvent, etc. +const MOCK_USER_ROLE_KEY = 'krow_mock_user_role'; + // --- Auth Module --- const authModule = { /** @@ -28,13 +30,16 @@ const authModule = { console.warn("Krow user not found in DataConnect, returning Firebase-only info."); } + let mockRole = null; + mockRole = localStorage.getItem(MOCK_USER_ROLE_KEY); + // 3. Build unified "me" object return { id: fbUser.uid, email: fbUser.email, fullName: krowUser?.fullName || fbUser.displayName || null, role: krowUser?.role || "user", - user_role: krowUser?.userRole || null, + user_role: mockRole || krowUser?.userRole || null, firebase: fbUser, krow: krowUser }; @@ -45,6 +50,9 @@ const authModule = { * @param {string} [redirectUrl] - Optional URL to redirect to after logout. */ logout: async (redirectUrl) => { + + localStorage.removeItem(MOCK_USER_ROLE_KEY); + await signOut(auth); if (redirectUrl) { window.location.href = redirectUrl; @@ -58,6 +66,34 @@ const authModule = { isAuthenticated: () => { return !!auth.currentUser; }, + + // ============================== + // FIX: auth.updateMe para soportar RoleSwitcher (antes lo hacĂ­a el mock base44) + // ============================== + /** + * Updates current user metadata (including role/user_role). + * Used by RoleSwitcher to change between ADMIN / VENDOR / etc. + * @param {{ user_role?: string, role?: string, fullName?: string }} data + * @returns {Promise} updated "me" object + */ + updateMe: async (data) => { + const fbUser = auth.currentUser; + if (!fbUser) { + throw new Error("Not authenticated"); + } + + if (data.user_role) { + try { + localStorage.setItem(MOCK_USER_ROLE_KEY, data.user_role); + } catch (err) { + console.warn("Krow user role could not be saved to localStorage."); + } + } + + return authModule.me(); + + }, + }; // --- Core Integrations Module --- diff --git a/frontend-web-free/src/pages/Layout.jsx b/frontend-web-free/src/pages/Layout.jsx index 9c23297e..92c5d6da 100644 --- a/frontend-web-free/src/pages/Layout.jsx +++ b/frontend-web-free/src/pages/Layout.jsx @@ -483,6 +483,10 @@ export default function Layout({ children }) { My Profile + + + Logout +