solving problem with selected roll
This commit is contained in:
@@ -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<object>} 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 ---
|
||||
|
||||
@@ -483,6 +483,10 @@ export default function Layout({ children }) {
|
||||
<User className="w-4 h-4 mr-2" />My Profile
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={handleLogout} className="text-red-600 focus:text-red-600">
|
||||
<LogOut className="w-4 h-4 mr-2" />
|
||||
<span>Logout</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user