Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platform] : (Fix) Login Issue for most Users #2551

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/platform/src/pages/account/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,31 @@ const UserLogin = () => {
const preferencesResponse = await retryWithDelay(() =>
dispatch(getIndividualUserPreferences({ identifier: user._id })),
);

let activeGroup;
if (preferencesResponse.payload.success) {
const preferences = preferencesResponse.payload.preferences;
const activeGroup = preferences[0]?.group_id
? user.groups.find((group) => group._id === preferences[0].group_id)
: user.groups.find((group) => group.grp_title === 'airqo');
localStorage.setItem('activeGroup', JSON.stringify(activeGroup));
// Try to get the group from the first preference if exists and valid
if (preferences.length > 0 && preferences[0].group_id) {
activeGroup = user.groups.find(
(group) => group._id === preferences[0].group_id,
);
}
}
// Fallback to group with title 'airqo'
if (!activeGroup) {
activeGroup = user.groups.find(
(group) => group.grp_title.toLowerCase() === 'airqo',
);
}
// If still not set, throw an error to alert support
if (!activeGroup) {
throw new Error(
'No active group found. Contact support to add you to the AirQo Organisation',
);
}

localStorage.setItem('activeGroup', JSON.stringify(activeGroup));

dispatch(setUserInfo(user));
dispatch(setSuccess(true));
Expand Down
Loading