Browse Source

Merge pull request 'fix/login' (#185) from StalinistApologist/hexbear-frontend:fix/login into main

Reviewed-on: https://git.chapo.chat/hexbear-collective/hexbear-frontend/pulls/185
Reviewed-by: DashEightMate <[email protected]>
main
DashEightMate 5 months ago
parent
commit
5849633e73
  1. 10
      src/components/login.tsx
  2. 6
      src/utils.ts

10
src/components/login.tsx

@ -451,7 +451,7 @@ export class Login extends Component<any, State> {
api
.post<LoginResponse>('user/login', this.state.loginForm)
.then(res => {
const data = res.data;
const { data } = res;
console.log(data);
if (data.requires_2fa) {
this.setState({
@ -468,8 +468,8 @@ export class Login extends Component<any, State> {
.catch((err: Error | AxiosError) => {
const res = (err as AxiosError).response;
if (res) {
const data = res.data as { error: string };
toast(i18n.t(data.error), 'danger');
const { message } = res.data;
toast(i18n.t(message), 'danger');
} else {
console.log(err);
}
@ -670,8 +670,8 @@ export class Login extends Component<any, State> {
}
toast(i18n.t(msg.error), 'danger');
// Refetch another captcha
WebSocketService.Instance.getCaptcha();
// Refetch another captcha; this can loop quickly without a timeout
setTimeout(() => WebSocketService.Instance.getCaptcha(), 3000);
} else {
if (res.op === UserOperation.GetCaptcha) {
const data = res.data as GetCaptchaResponse;

6
src/utils.ts

@ -538,8 +538,8 @@ export function isCommentType(item: Comment | PrivateMessage): item is Comment {
export function toast(text: string, background = 'success'): void {
let backgroundColor = `var(--${background})`;
Toastify({
text: text,
backgroundColor: backgroundColor,
text,
backgroundColor,
gravity: 'bottom',
position: 'left',
}).showToast();
@ -1245,7 +1245,7 @@ export const api = axios.create({
api.interceptors.response.use(undefined, error => {
if (error.response) {
const errName = error.response.data.error;
if (errName.includes('site_ban')) {
if (errName?.includes('site_ban')) {
const id = errName.replace('site_ban_', '');
error.response.data.error = 'site_ban';
localStorage.setItem('bid', id);

Loading…
Cancel
Save