Skip to content

Commit f68961a

Browse files
committed
refactor: fix MFA related codes as vue query updated
Signed-off-by: 이승연 <[email protected]>
1 parent 6a0a6e0 commit f68961a

File tree

6 files changed

+56
-43
lines changed

6 files changed

+56
-43
lines changed

apps/web/src/services/auth/authenticator/local/template/ID_PW.vue

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { useUserStore } from '@/store/user/user-store';
1717
1818
import config from '@/lib/config';
1919
import { isMobile } from '@/lib/helper/cross-browsing-helper';
20-
import { showErrorMessage } from '@/lib/helper/notice-alert-helper';
2120
2221
import ErrorHandler from '@/common/composables/error/errorHandler';
2322
@@ -85,21 +84,6 @@ const signIn = async () => {
8584
await loadAuth().signIn(credentials, 'LOCAL');
8685
displayStore.setIsSignInFailed(false);
8786
88-
// console.log('userStore.state.requiredActions', userStore.state.requiredActions, userStore.state.mfa);
89-
if (userStore.state.requiredActions?.includes(REQUIRED_ACTIONS.ENFORCE_MFA)) {
90-
const MFA_TYPE = userStore.state.mfa?.mfa_type;
91-
const isMFAEnforced = !!userStore.state.mfa?.options?.enforce && !!MFA_TYPE;
92-
const needToEnableMFA = isMFAEnforced && userStore.state.mfa?.state !== 'ENABLED';
93-
if (needToEnableMFA) { // Enforced MFA by admin. Always has both `options.enforce` and `mfa_type`.
94-
if (import.meta.env.DEV) console.debug(`[ID_PW.vue] MFA_TYPE: ${MFA_TYPE}`);
95-
await router.push({ name: AUTH_ROUTE.SIGN_IN.MULTI_FACTOR_AUTH_SETUP._NAME, params: { mfaType: MFA_TYPE } });
96-
} else {
97-
showErrorMessage('Something went wrong! Contact support.', 'MFA_NOT_SETUP');
98-
await router.push({ name: AUTH_ROUTE.SIGN_OUT._NAME });
99-
}
100-
return;
101-
}
102-
10387
if (userStore.state.requiredActions?.includes(REQUIRED_ACTIONS.UPDATE_PASSWORD)) {
10488
await router.push({ name: AUTH_ROUTE.PASSWORD.STATUS.RESET._NAME });
10589
} else {
@@ -109,15 +93,36 @@ const signIn = async () => {
10993
if (e.message.includes('MFA')) {
11094
const emailRegex = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g;
11195
const mfaTypeRegex = /mfa_type\s*=\s*(\w+)/;
112-
await router.push({
113-
name: AUTH_ROUTE.SIGN_IN.MULTI_FACTOR_AUTH._NAME,
114-
params: {
115-
password: credentials.password,
116-
mfaEmail: e.message.match(emailRegex)[0],
117-
mfaType: e.message.match(mfaTypeRegex)[1],
118-
userId: state.userId?.trim() as string,
119-
},
120-
});
96+
const message = e.message || '';
97+
98+
const mfaType = message.match(mfaTypeRegex)?.[1];
99+
const mfaEmail = message.match(emailRegex)?.[0];
100+
101+
const isStateEnabled = message.includes('ENABLED');
102+
const isStateDisabled = message.includes('DISABLED');
103+
104+
if (message.includes('MFA is not activated.') && isStateDisabled && mfaType) {
105+
const token = message.match(/access_token\s*=\s*([\w.-]+)/)?.[1];
106+
107+
await router.push({
108+
name: AUTH_ROUTE.SIGN_IN.MULTI_FACTOR_AUTH_SETUP._NAME,
109+
params: { mfaType },
110+
query: { sso_access_token: token },
111+
});
112+
} else if (message.includes('required') || (message.includes('MFA is not activated.') && isStateEnabled)) {
113+
await router.push({
114+
name: AUTH_ROUTE.SIGN_IN.MULTI_FACTOR_AUTH._NAME,
115+
params: {
116+
password: credentials.password, mfaEmail, mfaType, userId: state.userId?.trim() as string,
117+
},
118+
});
119+
} else if (message.includes('Authenticate failure')) {
120+
ErrorHandler.handleError(e);
121+
displayStore.setIsSignInFailed(true);
122+
} else {
123+
ErrorHandler.handleRequestError(e, e.message);
124+
await router.push({ name: AUTH_ROUTE.SIGN_OUT._NAME });
125+
}
121126
} else {
122127
displayStore.setSignInFailedMessage(e.message);
123128
ErrorHandler.handleError(e);

apps/web/src/services/auth/pages/MultiFactorAuthSetUpPage.vue

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import { MULTI_FACTOR_AUTH_TYPE } from '@/api-clients/identity/user-profile/sche
1414
import type { MultiFactorAuthType } from '@/api-clients/identity/user-profile/schema/type';
1515
import { i18n as _i18n } from '@/translations';
1616
17-
import { ROOT_ROUTE } from '@/router/constant';
18-
1917
import { useUserStore } from '@/store/user/user-store';
2018
2119
import { showErrorMessage } from '@/lib/helper/notice-alert-helper';
@@ -47,7 +45,7 @@ const {
4745
} = route.params as { mfaType: MultiFactorAuthType | undefined };
4846
4947
const state = reactive({
50-
isLocalLogin: computed<boolean>(() => userStore.state.authType === 'LOCAL'),
48+
// isLocalLogin: computed<boolean>(() => userStore.state.authType === 'LOCAL'),
5149
myMFAType: computed<MultiFactorAuthType|undefined>(() => userStore.state.mfa?.mfa_type),
5250
isInvalidMfaType: computed<boolean>(() => state.myMFAType !== mfaTypeRouteParam || !state.myMFAType || !mfaTypeRouteParam),
5351
needToEnableMFA: computed<boolean>(() => {
@@ -112,16 +110,16 @@ const handleClickConfirmButton = async () => {
112110
});
113111
};
114112
113+
const getSSOTokenFromUrl = (): string|undefined => {
114+
const query = router.currentRoute.query;
115+
return query.sso_access_token as string;
116+
};
117+
115118
onMounted(() => {
116-
// Remove refresh token to prevent forced access to other pages
117-
SpaceConnector.removeRefreshToken();
118-
119-
if (!SpaceConnector.getAccessToken() || !state.needToEnableMFA || state.isInvalidMfaType) {
120-
router.push({ name: AUTH_ROUTE.SIGN_OUT._NAME });
121-
return;
122-
} if (!state.isLocalLogin) {
123-
router.push({ name: ROOT_ROUTE._NAME });
124-
}
119+
const ssoAccessToken = getSSOTokenFromUrl();
120+
121+
if (!ssoAccessToken) return;
122+
SpaceConnector.setToken(ssoAccessToken, '');
125123
});
126124
127125
onBeforeUnmount(() => {

apps/web/src/services/auth/routes/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default [
7474
isCentered: true,
7575
},
7676
props: (route) => ({
77+
ssoAccessToken: route.query.sso_access_token,
7778
previousPath: route.query.previousPath,
7879
redirectPath: route.query.redirectPath,
7980
}),

apps/web/src/services/iam/components/UserManagementHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { useUserWorkspaceStore } from '@/store/app-context/workspace/user-worksp
1414
import { useQueryTags } from '@/common/composables/query-tags';
1515
1616
import { useUserListPaginationQuery } from '@/services/iam/composables/use-user-list-pagination-query';
17+
import { useUserListQuery } from '@/services/iam/composables/use-user-list-query';
1718
import { USER_MODAL_TYPE, USER_SEARCH_HANDLERS } from '@/services/iam/constants/user-constant';
1819
import { useUserPageStore } from '@/services/iam/store/user-page-store';
1920
20-
import { useUserListQuery } from '../composables/use-user-list-query';
2121
2222
2323
interface Props {

apps/web/src/services/iam/components/mfa/UserBulkMFASettingModal.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ErrorHandler from '@/common/composables/error/errorHandler';
1818
1919
import UserMFASettingFormLayout from '@/services/iam/components/mfa/UserMFASettingFormLayout.vue';
2020
import { useUserUpdateMutation } from '@/services/iam/composables/mutations/use-user-update-mutation';
21+
import { useUserListQuery } from '@/services/iam/composables/use-user-list-query';
2122
import { USER_MODAL_MAP } from '@/services/iam/constants/modal.constant';
2223
import { MULTI_FACTOR_AUTH_ITEMS } from '@/services/iam/constants/user-constant';
2324
import { useUserPageStore } from '@/services/iam/store/user-page-store';
@@ -33,19 +34,23 @@ const emit = defineEmits<UserBulkMFASettingModalEmits>();
3334
const userPageStore = useUserPageStore();
3435
const userPageState = userPageStore.state;
3536
const userPageModalState = userPageStore.modalState;
36-
const userPageGetters = userPageStore.getters;
3737
const userStore = useUserStore();
3838
3939
/* State */
4040
const selectedMfaType = ref<MultiFactorAuthType>(MULTI_FACTOR_AUTH_ITEMS[0].type);
4141
const isRequiredMfa = ref(false);
4242
43+
const selectedUserIds = computed<string[]>(() => userPageState.selectedUserIds);
44+
45+
const { userListData: selectedUsers } = useUserListQuery(selectedUserIds);
46+
47+
4348
/* Computed */
4449
// Only Local Auth Type Users can be updated
45-
const selectedMFAControllableUsers = computed<UserListItemType[]>(() => userPageGetters.selectedUsers.filter((user) => user.auth_type === 'LOCAL'));
50+
const selectedMFAControllableUsers = computed<UserListItemType[]>(() => selectedUsers.value?.filter((user) => user.auth_type === 'LOCAL') || []);
4651
4752
// UI Conditions
48-
const isIncludedExternalAuthTypeUser = computed<boolean>(() => userPageGetters.selectedUsers.some((user) => user.auth_type !== 'LOCAL'));
53+
const isIncludedExternalAuthTypeUser = computed<boolean>(() => selectedUsers.value?.some((user) => user.auth_type !== 'LOCAL') || false);
4954
5055
/* API */
5156
// Store failed user IDs

apps/web/src/services/iam/components/mfa/UserMFASecretKeyDeleteModal.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ErrorHandler from '@/common/composables/error/errorHandler';
1111
1212
1313
import { useUserMfaDisableMutation } from '@/services/iam/composables/mutations/use-user-mfa-disable-mutation';
14+
import { useUserListQuery } from '@/services/iam/composables/use-user-list-query';
1415
import { USER_MODAL_MAP } from '@/services/iam/constants/modal.constant';
1516
import { USER_MODAL_TYPE } from '@/services/iam/constants/user-constant';
1617
import { useUserPageStore } from '@/services/iam/store/user-page-store';
@@ -24,12 +25,15 @@ const emit = defineEmits<UserMFASecretKeyDeleteModalEmits>();
2425
2526
/* Store */
2627
const userPageStore = useUserPageStore();
28+
const userPageState = userPageStore.state;
2729
const userPageModalState = userPageStore.modalState;
28-
const userPageGetters = userPageStore.getters;
2930
3031
/* Computed */
3132
// Only Local Auth Type Users can be disabled (disable = delete secret key)
32-
const selectedMFAEnabledUsers = computed<UserListItemType[]>(() => userPageGetters.selectedUsers.filter((user) => user.auth_type === 'LOCAL' && user.mfa?.state === 'ENABLED') || []);
33+
const selectedUserIds = computed<string[]>(() => userPageState.selectedUserIds);
34+
35+
const { userListData: selectedUsers } = useUserListQuery(selectedUserIds);
36+
const selectedMFAEnabledUsers = computed<UserListItemType[]>(() => selectedUsers.value?.filter((user) => user.auth_type === 'LOCAL' && user.mfa?.state === 'ENABLED') || []);
3337
3438
/* API */
3539
// Store failed user IDs

0 commit comments

Comments
 (0)