Skip to content

Commit

Permalink
🐛 Fix login with incorrect username or password (#330)
Browse files Browse the repository at this point in the history
* ✨ Add log field for sql caller

* 🐛 Fix login with incorrect username or password
  • Loading branch information
tosone authored Mar 9, 2024
1 parent cf2cff4 commit ef12a26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func AuthWithConfig(config AuthConfig) echo.MiddlewareFunc {
if config.DS {
return xerrors.NewDSError(c, xerrors.DSErrCodeUnauthorized)
}
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized, err.Error())
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized, "Username or password is not correct")
}
uid = user.ID

Expand All @@ -105,7 +105,7 @@ func AuthWithConfig(config AuthConfig) echo.MiddlewareFunc {
if config.DS {
return xerrors.NewDSError(c, xerrors.DSErrCodeUnauthorized)
}
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized, "Username or password is not correct")
}
case strings.HasPrefix(authorization, "Bearer"):
jti, uid, err = tokenService.Validate(ctx, strings.TrimSpace(strings.TrimPrefix(authorization, "Bearer")))
Expand Down
7 changes: 4 additions & 3 deletions web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import 'react-toastify/dist/ReactToastify.css';

import './index.css';

import ReactDOM from 'react-dom/client';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import relativeTime from 'dayjs/plugin/relativeTime';

import ReactDOM from 'react-dom/client';
import { HashRouter as Router } from 'react-router-dom';

import App from './App';
Expand Down
2 changes: 1 addition & 1 deletion web/src/utils/refreshToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import axios from "axios";

let REFRESH_TOKEN_INTERVAL: ReturnType<typeof setInterval> | null;

const REFRESH_TOKEN_INTERVAL_TIMEOUT = 60 * 10 * 1000; // 10 mins
const REFRESH_TOKEN_INTERVAL_TIMEOUT = 6 * 10 * 1000 // 1 min

export function refreshToken(
localServer: string,
Expand Down
6 changes: 5 additions & 1 deletion web/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const setupAxiosInterceptor = (navigate: any) => {
return response;
}, error => {
if (error?.response?.status === 401) {
navigate('/login');
if (error?.response?.config?.url?.endsWith("/api/v1/users/login")) {
return Promise.resolve(error?.response);
} else {
navigate('/login');
}
} else if (error?.response?.status === 500) {
return Promise.reject(error);
} else {
Expand Down

0 comments on commit ef12a26

Please sign in to comment.