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.
|
import * as dcSdk from '@dataconnect/generated'; // listEvents, createEvent, etc.
|
||||||
|
|
||||||
|
const MOCK_USER_ROLE_KEY = 'krow_mock_user_role';
|
||||||
|
|
||||||
// --- Auth Module ---
|
// --- Auth Module ---
|
||||||
const authModule = {
|
const authModule = {
|
||||||
/**
|
/**
|
||||||
@@ -28,13 +30,16 @@ const authModule = {
|
|||||||
console.warn("Krow user not found in DataConnect, returning Firebase-only info.");
|
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
|
// 3. Build unified "me" object
|
||||||
return {
|
return {
|
||||||
id: fbUser.uid,
|
id: fbUser.uid,
|
||||||
email: fbUser.email,
|
email: fbUser.email,
|
||||||
fullName: krowUser?.fullName || fbUser.displayName || null,
|
fullName: krowUser?.fullName || fbUser.displayName || null,
|
||||||
role: krowUser?.role || "user",
|
role: krowUser?.role || "user",
|
||||||
user_role: krowUser?.userRole || null,
|
user_role: mockRole || krowUser?.userRole || null,
|
||||||
firebase: fbUser,
|
firebase: fbUser,
|
||||||
krow: krowUser
|
krow: krowUser
|
||||||
};
|
};
|
||||||
@@ -45,6 +50,9 @@ const authModule = {
|
|||||||
* @param {string} [redirectUrl] - Optional URL to redirect to after logout.
|
* @param {string} [redirectUrl] - Optional URL to redirect to after logout.
|
||||||
*/
|
*/
|
||||||
logout: async (redirectUrl) => {
|
logout: async (redirectUrl) => {
|
||||||
|
|
||||||
|
localStorage.removeItem(MOCK_USER_ROLE_KEY);
|
||||||
|
|
||||||
await signOut(auth);
|
await signOut(auth);
|
||||||
if (redirectUrl) {
|
if (redirectUrl) {
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
@@ -58,6 +66,34 @@ const authModule = {
|
|||||||
isAuthenticated: () => {
|
isAuthenticated: () => {
|
||||||
return !!auth.currentUser;
|
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 ---
|
// --- Core Integrations Module ---
|
||||||
|
|||||||
@@ -483,6 +483,10 @@ export default function Layout({ children }) {
|
|||||||
<User className="w-4 h-4 mr-2" />My Profile
|
<User className="w-4 h-4 mr-2" />My Profile
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuSeparator />
|
<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>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user