This commit is contained in:
@@ -5,17 +5,46 @@ const login = (data) => {
|
||||
};
|
||||
|
||||
const getCurrentUserFromServer = () => {
|
||||
return http.get('/auth/me');
|
||||
return http.get('/auth/me', {
|
||||
params: {
|
||||
_ts: Date.now()
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const refreshCurrentUserPermissions = async () => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) return null;
|
||||
const existingUser = getCurrentUser() || {};
|
||||
const persistUser = (nextUserData) => {
|
||||
const mergedUser = {
|
||||
...existingUser,
|
||||
...nextUserData
|
||||
};
|
||||
localStorage.setItem('user', JSON.stringify(mergedUser));
|
||||
return mergedUser;
|
||||
};
|
||||
|
||||
try {
|
||||
const { data } = await getCurrentUserFromServer();
|
||||
if (data) {
|
||||
localStorage.setItem('user', JSON.stringify(data));
|
||||
return persistUser(data);
|
||||
}
|
||||
return data;
|
||||
} catch (error) {
|
||||
const userId = existingUser?.id;
|
||||
if (!userId) throw error;
|
||||
const { data } = await http.get(`/employees/${userId}`, {
|
||||
params: {
|
||||
_ts: Date.now()
|
||||
}
|
||||
});
|
||||
if (data) {
|
||||
return persistUser(data);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
return existingUser;
|
||||
};
|
||||
|
||||
const logout = (data, shouldClearSession = false) => {
|
||||
|
||||
Reference in New Issue
Block a user