mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
error handling in auth
This commit is contained in:
@@ -21,6 +21,7 @@ import isBlankString from '../../../utils/isBlankString';
|
||||
import genJsonPayload from '../../../utils/genJsonPayload';
|
||||
import getFormUrl from '../../../utils/getFormUrl';
|
||||
import registerShowPassword from '../../../components/showPassword';
|
||||
import createError from '../../../components/error/index';
|
||||
|
||||
//import '../forms.scss';
|
||||
|
||||
@@ -52,11 +53,10 @@ const login = async (e: Event) => {
|
||||
|
||||
const res = await fetch(formUrl, genJsonPayload(payload));
|
||||
if (res.ok) {
|
||||
alert('success');
|
||||
window.location.assign(VIEWS.panelHome);
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(`error: ${err.error}`);
|
||||
createError(err.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import emailExists from './emailExists';
|
||||
|
||||
import {mockAlert, getRegistrationFormHtml} from '../../../setUpTests';
|
||||
|
||||
import setup from '../../../components/error/setUpTests';
|
||||
|
||||
fetchMock.enableMocks();
|
||||
mockAlert();
|
||||
|
||||
@@ -32,6 +34,8 @@ it('finds exchange', async () => {
|
||||
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
|
||||
|
||||
document.body.innerHTML = getRegistrationFormHtml();
|
||||
document.querySelector('body').appendChild(setup());
|
||||
|
||||
const emailField = <HTMLInputElement>document.getElementById('email');
|
||||
emailField.setAttribute('value', 'test@a.com');
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import ROUTES from '../../../api/v1/routes';
|
||||
|
||||
import genJsonPayload from '../../../utils/genJsonPayload';
|
||||
import createError from '../../../components/error/index';
|
||||
|
||||
const emailExists = async () => {
|
||||
const email = <HTMLInputElement>document.getElementById('email');
|
||||
@@ -31,13 +32,13 @@ const emailExists = async () => {
|
||||
const data = await res.json();
|
||||
if (data.exists) {
|
||||
email.className += ' form__in-field--warn';
|
||||
alert('Email taken');
|
||||
createError(`Email "${val}" is already used`);
|
||||
return data.exists;
|
||||
}
|
||||
return data.exists;
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(`error: ${err.error}`);
|
||||
createError(err.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import userExists from './userExists';
|
||||
import emailExists from './emailExists';
|
||||
import getFormUrl from '../../../utils/getFormUrl';
|
||||
import registerShowPassword from '../../../components/showPassword';
|
||||
import createError from '../../../components/error/index';
|
||||
|
||||
//import '../forms.scss';
|
||||
|
||||
@@ -72,11 +73,10 @@ const registerUser = async (e: Event) => {
|
||||
|
||||
const res = await fetch(formUrl, genJsonPayload(payload));
|
||||
if (res.ok) {
|
||||
alert('success');
|
||||
window.location.assign(VIEWS.loginUser);
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(`error: ${err.error}`);
|
||||
createError(err.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import userExists from './userExists';
|
||||
|
||||
import {mockAlert, getLoginFormHtml} from '../../../setUpTests';
|
||||
|
||||
import setup from '../../../components/error/setUpTests';
|
||||
|
||||
fetchMock.enableMocks();
|
||||
mockAlert();
|
||||
|
||||
@@ -32,6 +34,7 @@ it('finds exchange', async () => {
|
||||
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
|
||||
|
||||
document.body.innerHTML = getLoginFormHtml();
|
||||
document.querySelector('body').appendChild(setup());
|
||||
const usernameField = <HTMLInputElement>document.querySelector('#username');
|
||||
usernameField.value = 'test';
|
||||
expect(await userExists()).toBe(true);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import ROUTES from '../../../api/v1/routes';
|
||||
|
||||
import genJsonPayload from '../../../utils/genJsonPayload';
|
||||
import createError from '../../../components/error/index';
|
||||
|
||||
const userExists = async () => {
|
||||
const username = <HTMLInputElement>document.getElementById('username');
|
||||
@@ -31,12 +32,12 @@ const userExists = async () => {
|
||||
const data = await res.json();
|
||||
if (data.exists) {
|
||||
username.className += ' form__in-field--warn';
|
||||
alert('Username taken');
|
||||
createError(`Username "${val}" taken`);
|
||||
}
|
||||
return data.exists;
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(`error: ${err.error}`);
|
||||
createError(err.error);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user