Fixes: 1) Replace usage of `vue-router` with `window.location.href` for redirects across multiple composables; 2) Ensure proper locale switching in authentication flows; Extra: 1) Update `package-lock.json` with dependencies for Apollo, Vue I18n, and styling; 2) Remove unused `i18n.config.js` to streamline i18n setup; 3) General composables refactoring to improve code maintainability;
70 lines
No EOL
1.7 KiB
JavaScript
70 lines
No EOL
1.7 KiB
JavaScript
import {useMutation} from "@vue/apollo-composable";
|
|
import {NEW_PASSWORD} from "@/graphql/mutations/auth.js";
|
|
import {computed, ref} from "vue";
|
|
import {ElNotification} from "element-plus";
|
|
import {useI18n} from "vue-i18n";
|
|
import {DEFAULT_LOCALE, LOCALE_STORAGE_LOCALE_KEY} from "@/config/index.js";
|
|
|
|
export function useNewPassword() {
|
|
const {t} = useI18n();
|
|
|
|
const { mutate: newPasswordMutation } = useMutation(NEW_PASSWORD);
|
|
|
|
const token = computed(() =>
|
|
route.query.token ? (route.query.token) : undefined,
|
|
);
|
|
const uid = computed(() =>
|
|
route.query.uid ? (route.query.uid) : undefined,
|
|
);
|
|
|
|
const loading = ref(false);
|
|
|
|
async function newPassword(
|
|
password,
|
|
confirmPassword
|
|
) {
|
|
loading.value = true;
|
|
|
|
try {
|
|
const response = await newPasswordMutation({
|
|
password,
|
|
confirmPassword,
|
|
token: token.value,
|
|
uid: uid.value
|
|
});
|
|
|
|
if (response.data?.confirmResetPassword.success) {
|
|
ElNotification({
|
|
message: t('popup.success.newPassword'),
|
|
type: 'success'
|
|
})
|
|
|
|
await router.push({
|
|
name: 'home',
|
|
params: {
|
|
locale: localStorage.getItem(LOCALE_STORAGE_LOCALE_KEY) || DEFAULT_LOCALE
|
|
}
|
|
})
|
|
}
|
|
} catch (error) {
|
|
console.error("useNewPassword error:", error);
|
|
|
|
const errorMessage = error.graphQLErrors?.[0]?.message ||
|
|
error.message ||
|
|
t('popup.errors.defaultError');
|
|
|
|
ElNotification({
|
|
title: t('popup.errors.main'),
|
|
message: errorMessage,
|
|
type: 'error'
|
|
});
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
return {
|
|
newPassword,
|
|
loading
|
|
};
|
|
} |