refactor: standardize theme colors, update UI components, and refine auth redirection logic
This commit is contained in:
@@ -43,40 +43,44 @@ export async function terminateAuthSession(options: TerminateOptions = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function initiateAuthSession(respLogin: any) {
|
export async function initiateAuthSession(respLogin: any) {
|
||||||
const data = respLogin?.data ?? {};
|
try {
|
||||||
const { token, id } = data;
|
const data = respLogin?.data ?? {};
|
||||||
const userProfile = lodash.omit(data, ['token']);
|
const { token, id } = data;
|
||||||
|
const userProfile = lodash.omit(data, ['token']);
|
||||||
|
|
||||||
if (!token) throw new Error('Login response missing token');
|
if (!token) throw new Error('Login response missing token');
|
||||||
|
|
||||||
// FIXME: Populate this with the mapped privilege data.
|
// FIXME: Populate this with the mapped privilege data.
|
||||||
// NOTE: The assignment below needs to be updated. Replace the empty object `{}`
|
// NOTE: The assignment below needs to be updated. Replace the empty object `{}`
|
||||||
// with the actual mapped data (e.g., from mappingUserPrivilege(data)).
|
// with the actual mapped data (e.g., from mappingUserPrivilege(data)).
|
||||||
// Expected structure (Record<string, PrivilegeEntity>):
|
// Expected structure (Record<string, PrivilegeEntity>):
|
||||||
// {
|
// {
|
||||||
// "TRANSACTION_BOOKING": {
|
// "TRANSACTION_BOOKING": {
|
||||||
// ALLOW_CREATE: true,
|
// ALLOW_CREATE: true,
|
||||||
// ALLOW_VIEW: true,
|
// ALLOW_VIEW: true,
|
||||||
// // ...
|
// // ...
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
const userPrivilege: Record<string, PrivilegeEntity> = {};
|
const userPrivilege: Record<string, PrivilegeEntity> = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store credentials in local storage
|
* Store credentials in local storage
|
||||||
*/
|
*/
|
||||||
await appStorage.setItem(AppStorageKey.USER_ID, id);
|
await appStorage.setItem(AppStorageKey.USER_ID, id);
|
||||||
await appDatabase.setItem(AppDatabaseKey.ACCESS_TOKEN, token);
|
await appDatabase.setItem(AppDatabaseKey.ACCESS_TOKEN, token);
|
||||||
await appDatabase.setItem(AppDatabaseKey.USER_PROFILE, { ...userProfile, label: userProfile.role });
|
await appDatabase.setItem(AppDatabaseKey.USER_PROFILE, { ...userProfile, label: userProfile.role });
|
||||||
await appDatabase.setItem(AppDatabaseKey.USER_PRIVILEGE, userPrivilege);
|
await appDatabase.setItem(AppDatabaseKey.USER_PRIVILEGE, userPrivilege);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine redirect destination
|
* Determine redirect destination
|
||||||
* If the user was redirected here from a protected page, honour that URL.
|
* If the user was redirected here from a protected page, honour that URL.
|
||||||
* Otherwise fall back to the default app entry point.
|
* Otherwise fall back to the default app entry point.
|
||||||
*/
|
*/
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const redirectTo = params.get('redirect');
|
const redirectTo = params.get('redirect');
|
||||||
|
|
||||||
window.location.replace(redirectTo ? decodeURIComponent(redirectTo) : '/app');
|
window.location.replace(redirectTo ? decodeURIComponent(redirectTo) : '/app');
|
||||||
|
} catch (error) {
|
||||||
|
throw error as any;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user