updates on auth for the login creds and data linkage and updates on the deliveries page and queries section and updates on the test files

This commit is contained in:
2026-08-28 11:38:53 +05:30
parent f48e061138
commit 5d5a748352
5 changed files with 93 additions and 7 deletions

View File

@@ -23,6 +23,26 @@ import {
* shell that renders but 401s on every fetch is worse than being sent back.
*/
/**
* Determines whether the signed-in user is a client/merchant account
* rather than Doormile internal staff.
*/
export const isClientUser = (user) => {
if (!user) {
const storedTenant = localStorage.getItem('tenantid');
const storedAuth = (localStorage.getItem('authname') || '').toLowerCase();
if (storedTenant && storedTenant !== '0' && storedTenant !== 'null' && storedTenant !== '') return true;
if (storedAuth.includes('dailygrubs.com')) return true;
return false;
}
const email = (user.email || user.primaryemail || user.authname || '').toLowerCase();
if (email.includes('dailygrubs.com') || email === 'info@dailygrubs.com') return true;
if (user.tenantid != null && user.tenantid !== '' && user.tenantid !== 0 && user.tenantid !== '0') return true;
const role = String(user.role || user.roleid || '').toLowerCase();
if (role === 'client' || role === 'tenant' || role === 'merchant') return true;
return false;
};
const AuthContext = createContext(/** @type {any} */ (null));
/** @param {any} props */
@@ -90,9 +110,12 @@ export const AuthProvider = ({ children }) => {
const navigateToLogin = useCallback(() => window.location.replace('/login'), []);
const isClient = useMemo(() => isClientUser(user), [user]);
const value = useMemo(
() => ({
user,
isClient,
isAuthenticated,
isLoadingAuth,
/* No remote app settings on this backend — kept so consumers that gate on
@@ -107,7 +130,7 @@ export const AuthProvider = ({ children }) => {
checkUserAuth,
checkAppState: checkUserAuth,
}),
[user, isAuthenticated, isLoadingAuth, authError, authChecked, login, logout, navigateToLogin, checkUserAuth]
[user, isClient, isAuthenticated, isLoadingAuth, authError, authChecked, login, logout, navigateToLogin, checkUserAuth]
);
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;