Skip to content

Commit 8d5cd7a

Browse files
author
Petr Kachanovsky
committed
fix: add i18n for login page errors
1 parent 3a32d10 commit 8d5cd7a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

adminforth/modules/restApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
111111
path: '/login',
112112
handler: async ({ body, response, headers, query, cookies, requestUrl }) => {
113113

114-
const INVALID_MESSAGE = 'Invalid Username or Password';
114+
const INVALID_MESSAGE = 'invalid_username_or_password';
115115
const { username, password, rememberMe } = body;
116116
let adminUser: AdminUser;
117117
let toReturn: { redirectTo?: string, allowedLogin:boolean, error?: string } = { allowedLogin: true };

adminforth/spa/src/views/LoginView.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
name="username"
4646
id="username"
4747
ref="usernameInput"
48+
oninput="setCustomValidity('')"
4849
@keydown.enter="passwordInput.focus()"
4950
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white" placeholder="name@company.com" required />
5051
</div>
@@ -120,6 +121,9 @@ import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbi
120121
import { callAdminForthApi, loadFile } from '@/utils';
121122
import { useRoute, useRouter } from 'vue-router';
122123
import { Button, Checkbox } from '@/afcl';
124+
import { useI18n } from 'vue-i18n';
125+
126+
const { t } = useI18n();
123127
124128
const passwordInput = ref(null);
125129
const usernameInput = ref(null);
@@ -167,9 +171,15 @@ async function login() {
167171
const username = usernameInput.value.value;
168172
const password = passwordInput.value.value;
169173
170-
if (!username || !password) {
174+
if (!username) {
175+
usernameInput.value.setCustomValidity(t('Please fill out this field.'));
176+
return;
177+
}
178+
if (!password) {
179+
passwordInput.value.setCustomValidity(t('Please fill out this field.'));
171180
return;
172181
}
182+
173183
if (inProgress.value) {
174184
return;
175185
}
@@ -184,7 +194,11 @@ async function login() {
184194
}
185195
});
186196
if (resp.error) {
187-
error.value = resp.error;
197+
if (resp.error === 'invalid_username_or_password') {
198+
error.value = t('Invalid username or password');
199+
} else {
200+
error.value = resp.error;
201+
}
188202
} else if (resp.redirectTo) {
189203
router.push(resp.redirectTo);
190204
} else {

0 commit comments

Comments
 (0)