Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

管理后台token失效不自动跳转登录页 #3428

Closed
keepleaning opened this issue Jul 23, 2020 · 1 comment
Closed

管理后台token失效不自动跳转登录页 #3428

keepleaning opened this issue Jul 23, 2020 · 1 comment
Labels
area/Nacos console Related to Nacos consle contribution welcome kind/bug Category issues or prs related to bug.

Comments

@keepleaning
Copy link

管理端token失效不自动跳转登录页

Type: bug report
版本:1.3.1

经查代码发现是前端统一处理 403 forbidden 的时候一个bug:
后端代码处理login时抛异常,message是"token invalid!",前端处理403的时候判断的是"token invalid"。

综上:前端判断403的时候少了个"!"。

后端代码:com.alibaba.nacos.console.security.nacos.NacosAuthManager#login 第74行

try {
            tokenManager.validateToken(token);
        } catch (ExpiredJwtException e) {
            throw new AccessException("token expired!");
        } catch (Exception e) {
            throw new AccessException("token invalid!");
        }

前端代码:nacos\console\src\main\resources\static\console-fe\src\globalLib.js 第531行

      error => {
        // 处理403 forbidden
        const { status, responseJSON = {} } = error || {};
        if (responseJSON.message) {
          Message.error(responseJSON.message);
        }
        if (
          [401, 403].includes(status) &&
          ['unknown user!', 'token invalid', 'token expired!'].includes(responseJSON.message)
        ) {
          goLogin();
        }
        return error;
      }

nacos\console\src\main\resources\static\console-fe\src\utils\request.js 第88行

    error => {
      if (error.response) {
        const { data = {}, status } = error.response;
        let message = `HTTP ERROR: ${status}`;
        if (typeof data === 'string') {
          message = data;
        } else if (typeof data === 'object') {
          message = data.message;
        }
        Message.error(message);

        if (
          [401, 403].includes(status) &&
          ['unknown user!', 'token invalid', 'token expired!'].includes(message)
        ) {
          goLogin();
        }
        return Promise.reject(error.response);
      }
      Message.error(API_GENERAL_ERROR_MESSAGE);
      return Promise.reject(error);
    }
@KomachiSion KomachiSion added area/Nacos console Related to Nacos consle kind/research kind/bug Category issues or prs related to bug. contribution welcome labels Jul 23, 2020
@senekis316
Copy link
Contributor

@i will solve it@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Nacos console Related to Nacos consle contribution welcome kind/bug Category issues or prs related to bug.
Projects
None yet
Development

No branches or pull requests

3 participants