mirror of
https://github.com/directus/directus.git
synced 2026-01-26 10:48:03 -05:00
Merge pull request #166 from directus/tfa-login
Use new error structure, show otp field on login
This commit is contained in:
@@ -51,7 +51,7 @@ export const onError = async (error: RequestError) => {
|
||||
/* istanbul ignore next */
|
||||
const status = error.response?.status;
|
||||
/* istanbul ignore next */
|
||||
const code = error.response?.data?.error?.code;
|
||||
const code = error.response?.data?.errors?.[0]?.extensions?.code;
|
||||
|
||||
if (status === 401 && code === 'INVALID_CREDENTIALS' && error.request.responseURL.includes('refresh') === false) {
|
||||
try {
|
||||
|
||||
@@ -24,7 +24,7 @@ export default defineComponent({
|
||||
},
|
||||
setup(props) {
|
||||
const code = computed(() => {
|
||||
return props.error?.response?.data?.error?.code || 'UNKNOWN';
|
||||
return props.error?.response?.data?.errors?.[0]?.extensions?.code || 'UNKNOWN';
|
||||
});
|
||||
|
||||
const copied = ref(false);
|
||||
|
||||
@@ -434,22 +434,16 @@
|
||||
"auto_format_casing": "Auto-format casing",
|
||||
|
||||
"errors": {
|
||||
"3": "Only super admins have access to this",
|
||||
"4": "Super Admin Token not provided",
|
||||
"11": "Can't Reach Database",
|
||||
"12": "Field has invalid regular expression",
|
||||
"100": "Incorrect Email/Password",
|
||||
"101": "Logged-out from Inactivity",
|
||||
"102": "Logged-out from Inactivity",
|
||||
"103": "User Suspended",
|
||||
"105": "Reset link expired",
|
||||
"106": "Incorrect Email/Password",
|
||||
"107": "User Not Found",
|
||||
"111": "Enter One-Time Password",
|
||||
"112": "Wrong One-Time Password",
|
||||
"114": "Incorrect Email/Password",
|
||||
"115": "SSO is not allowed when 2FA is enabled",
|
||||
"503": "Email couldn't be sent. Please verify the API's configuration",
|
||||
"COLLECTION_NOT_FOUND": "Collection doesn't exist.",
|
||||
"FIELD_NOT_FOUND": "Field not found.",
|
||||
"NO_PERMISSION": "Forbidden.",
|
||||
"INVALID_CREDENTIALS": "Wrong username or password.",
|
||||
"INVALID_OTP": "Wrong one-time password.",
|
||||
"INVALID_PAYLOAD": "Invalid payload.",
|
||||
"INVALID_QUERY": "Invalid query.",
|
||||
"ITEM_LIMIT_REACHED": "Item limit reached.",
|
||||
"ITEM_NOT_FOUND": "Item not found.",
|
||||
"ROUTE_NOT_FOUND": "Not found.",
|
||||
"-1": "Couldn't Reach API"
|
||||
},
|
||||
|
||||
|
||||
@@ -100,13 +100,13 @@ export async function setLanguage(lang: Language): Promise<boolean> {
|
||||
|
||||
export default i18n;
|
||||
|
||||
export function translateAPIError(error: RequestError | number) {
|
||||
export function translateAPIError(error: RequestError | string) {
|
||||
const defaultMsg = i18n.t('unexpected_error');
|
||||
|
||||
let code = error;
|
||||
|
||||
if (typeof error === 'object') {
|
||||
code = error?.response?.data?.error?.code;
|
||||
code = error?.response?.data?.errors?.[0]?.extensions?.code;
|
||||
}
|
||||
|
||||
if (!error) return defaultMsg;
|
||||
|
||||
@@ -127,7 +127,10 @@ export default defineComponent({
|
||||
router.push(lastPage || '/collections');
|
||||
} catch (err) {
|
||||
/** @todo use new error code */
|
||||
if (err.response?.data?.error?.code === 111) {
|
||||
if (
|
||||
err.response?.data?.errors?.[0]?.extensions?.code === 'INVALID_OTP' &&
|
||||
requiresTFA.value === false
|
||||
) {
|
||||
requiresTFA.value = true;
|
||||
} else {
|
||||
error.value = err;
|
||||
|
||||
Reference in New Issue
Block a user