mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
feat: move AuthErrorCode to constants and update imports
This commit is contained in:
parent
76edc52a72
commit
e4e508ac8e
@ -10,6 +10,7 @@
|
||||
import { Context } from '@nocobase/actions';
|
||||
import { Model } from '@nocobase/database';
|
||||
import { Authenticator } from './auth-manager';
|
||||
import { AuthErrorCode } from './constants';
|
||||
export type AuthConfig = {
|
||||
authenticator: Authenticator;
|
||||
options: {
|
||||
@ -17,17 +18,6 @@ export type AuthConfig = {
|
||||
};
|
||||
ctx: Context;
|
||||
};
|
||||
export const AuthErrorCode = {
|
||||
EMPTY_TOKEN: 'EMPTY_TOKEN' as const,
|
||||
EXPIRED_TOKEN: 'EXPIRED_TOKEN' as const,
|
||||
INVALID_TOKEN: 'INVALID_TOKEN' as const,
|
||||
TOKEN_RENEW_FAILED: 'TOKEN_RENEW_FAILED' as const,
|
||||
BLOCKED_TOKEN: 'BLOCKED_TOKEN' as const,
|
||||
EXPIRED_SESSION: 'EXPIRED_SESSION' as const,
|
||||
NOT_EXIST_USER: 'NOT_EXIST_USER' as const,
|
||||
SKIP_TOKEN_RENEW: 'SKIP_TOKEN_RENEW' as const,
|
||||
USER_HAS_NO_ROLES_ERR: 'USER_HAS_NO_ROLES_ERR' as const,
|
||||
};
|
||||
|
||||
export type AuthErrorType = keyof typeof AuthErrorCode;
|
||||
|
||||
|
@ -10,7 +10,8 @@
|
||||
import { Cache } from '@nocobase/cache';
|
||||
import { Collection, Model } from '@nocobase/database';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { Auth, AuthConfig, AuthError, AuthErrorCode } from '../auth';
|
||||
import { AuthErrorCode } from '../constants';
|
||||
import { Auth, AuthConfig, AuthError } from '../auth';
|
||||
import { JwtService } from './jwt-service';
|
||||
import { ITokenControlService } from './token-control-service';
|
||||
|
||||
|
@ -7,4 +7,4 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
export { AuthErrorCode } from './auth';
|
||||
export { AuthErrorCode } from './constants';
|
||||
|
20
packages/core/auth/src/constants/index.ts
Normal file
20
packages/core/auth/src/constants/index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
export const AuthErrorCode = {
|
||||
EMPTY_TOKEN: 'EMPTY_TOKEN' as const,
|
||||
EXPIRED_TOKEN: 'EXPIRED_TOKEN' as const,
|
||||
INVALID_TOKEN: 'INVALID_TOKEN' as const,
|
||||
TOKEN_RENEW_FAILED: 'TOKEN_RENEW_FAILED' as const,
|
||||
BLOCKED_TOKEN: 'BLOCKED_TOKEN' as const,
|
||||
EXPIRED_SESSION: 'EXPIRED_SESSION' as const,
|
||||
NOT_EXIST_USER: 'NOT_EXIST_USER' as const,
|
||||
SKIP_TOKEN_RENEW: 'SKIP_TOKEN_RENEW' as const,
|
||||
USER_HAS_NO_ROLES_ERR: 'USER_HAS_NO_ROLES_ERR' as const,
|
||||
};
|
@ -7,6 +7,7 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
export { AuthErrorCode } from './constants';
|
||||
export * from './actions';
|
||||
export * from './auth';
|
||||
export * from './auth-manager';
|
||||
|
@ -12,6 +12,7 @@ import { css } from '@emotion/css';
|
||||
import { observer } from '@formily/reactive-react';
|
||||
import { getSubAppName } from '@nocobase/sdk';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { AuthErrorCode } from '@nocobase/auth/client';
|
||||
import { Button, Modal, Result, Spin } from 'antd';
|
||||
import React, { FC } from 'react';
|
||||
import { Navigate, useNavigate } from 'react-router-dom';
|
||||
@ -47,7 +48,7 @@ const useErrorProps = (app: Application, error: any) => {
|
||||
const err = error?.response?.data?.errors?.[0] || error;
|
||||
const subApp = getSubAppName(app.getPublicPath());
|
||||
switch (err.code) {
|
||||
case 'USER_HAS_NO_ROLES_ERR':
|
||||
case AuthErrorCode.USER_HAS_NO_ROLES_ERR:
|
||||
return {
|
||||
title: app.i18n.t('Permission denied'),
|
||||
subTitle: err.message,
|
||||
|
@ -10,18 +10,7 @@
|
||||
import { Application } from '@nocobase/client';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import debounce from 'lodash/debounce';
|
||||
|
||||
const AuthErrorCode = {
|
||||
EMPTY_TOKEN: 'EMPTY_TOKEN' as const,
|
||||
EXPIRED_TOKEN: 'EXPIRED_TOKEN' as const,
|
||||
INVALID_TOKEN: 'INVALID_TOKEN' as const,
|
||||
TOKEN_RENEW_FAILED: 'TOKEN_RENEW_FAILED' as const,
|
||||
BLOCKED_TOKEN: 'BLOCKED_TOKEN' as const,
|
||||
EXPIRED_SESSION: 'EXPIRED_SESSION' as const,
|
||||
NOT_EXIST_USER: 'NOT_EXIST_USER' as const,
|
||||
SKIP_TOKEN_RENEW: 'SKIP_TOKEN_RENEW' as const,
|
||||
USER_HAS_NO_ROLES_ERR: 'USER_HAS_NO_ROLES_ERR' as const,
|
||||
};
|
||||
import { AuthErrorCode } from '@nocobase/auth/client';
|
||||
|
||||
function removeBasename(pathname, basename) {
|
||||
// Escape special characters in basename for use in regex
|
||||
|
Loading…
x
Reference in New Issue
Block a user