Skip to content

Commit

Permalink
fix: 创建租户后提示域名
Browse files Browse the repository at this point in the history
  • Loading branch information
lixueping committed Nov 15, 2024
1 parent 5756737 commit 8bea7df
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 16 deletions.
6 changes: 6 additions & 0 deletions packages/guard-core-v4/src/Guard/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { getDefaultRegisterConfig, RegisterConfig } from '../Register/interface'

import { ShieldSpin } from '../ShieldSpin'

import { Modal } from 'shim-antd'

Modal.config({
rootPrefixCls: 'authing-ant'
})

export interface GuardLocalConfig
extends RegisterConfig,
LoginConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { React } from 'shim-react'
import { BackCustom } from '../../Back'
import { useTranslation } from 'react-i18next'
import { Form, Input } from 'shim-antd'
import { Form, Input, Modal } from 'shim-antd'
import SubmitButton from '../../SubmitButton'
import { CreateTenantProps } from '../interface'
import '../styles.less'
Expand All @@ -10,9 +10,11 @@ import {
useGuardCurrentModule,
useGuardEvents,
useGuardHttpClient,
useGuardModule,
useGuardPublicConfig
} from '../../_utils'
import { useGuardAuthClient } from '../../Guard/authClient'
import { GuardModuleType } from '../../Guard'

const { useMemo, useRef } = React

Expand All @@ -24,6 +26,7 @@ export const CreateTenantView: React.FC<CreateTenantProps> = ({ onBack }) => {
const publicConfig = useGuardPublicConfig()
const cdnBase = publicConfig?.cdnBase
const { moduleName } = useGuardCurrentModule()
const { changeModule } = useGuardModule()

const [form] = Form.useForm()
const submitButtonRef = useRef<any>(null)
Expand All @@ -42,6 +45,7 @@ export const CreateTenantView: React.FC<CreateTenantProps> = ({ onBack }) => {
// 需要重新认证
const tenantInfo = { ...data }
events?.onTenantSelect?.(tenantInfo)
const prevBaseUrl = http.getBaseUrl()
if (tenantInfo?.host) {
http.setBaseUrl(tenantInfo?.host)
}
Expand All @@ -55,7 +59,28 @@ export const CreateTenantView: React.FC<CreateTenantProps> = ({ onBack }) => {
isFlowEnd: end,
onGuardHandling,
data: res
} = await http.authFlow(moduleName)
} = await http.authFlow(moduleName, null, () =>
Modal.info({
title: t('login.tenantCreateSuccess'),
content: (
<div>
<p>
{t('login.tenantConsoleDomain')}
{tenantInfo.consoleHost}
</p>
<p>
{t('login.tenantAppDomain')}
{tenantInfo.host}
</p>
</div>
),
onOk() {
http.setTenantId('')
http.setBaseUrl(prevBaseUrl)
changeModule?.(GuardModuleType.LOGIN)
}
})
)
if (end) {
setTimeout(() => events?.onLogin?.(res, authClient)) // 让选择事件先行,登录成功宏任务异步,方便异步并发
} else {
Expand Down
28 changes: 21 additions & 7 deletions packages/guard-core-v4/src/_utils/guardHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ enum InterceptorName {
ERROR_CODE = 'errorCode'
}

type ResponseInterceptor = (res: AuthingResponse) => AuthingResponse
type ResponseInterceptor = (
res: AuthingResponse,
fetchErrorHandler?: () => void
) => AuthingResponse

export class GuardHttp {
private requestClient: any
Expand Down Expand Up @@ -68,6 +71,10 @@ export class GuardHttp {
return this
}

getBaseUrl() {
return this.getRequestClient().getBaseUrl()
}

public getHeaders = () => this.headers

public get = async <T = any>(
Expand Down Expand Up @@ -117,7 +124,8 @@ export class GuardHttp {

public authFlow = async <T = any>(
action: string,
data?: any
data?: any,
fetchErrorHandler?: () => void
): Promise<AuthingGuardResponse<T>> => {
const flowPath = '/interaction/authFlow'

Expand All @@ -135,7 +143,7 @@ export class GuardHttp {
}
})

return this.responseIntercept(res)
return this.responseIntercept(res, fetchErrorHandler)
}

// 初始化 Error code 拦截器
Expand All @@ -147,20 +155,26 @@ export class GuardHttp {

this.responseInterceptorMap.set(
InterceptorName.ERROR_CODE,
res => errorCodeInterceptor(res, callBack) // 传入调度拦截器回调
(res, fetchErrorHandler?: () => void) => {
return errorCodeInterceptor(res, callBack, fetchErrorHandler) // 传入调度拦截器回调
}
)

return this
}

public responseIntercept: (res: AuthingResponse) => AuthingGuardResponse = (
res: AuthingGuardResponse
public responseIntercept: (
res: AuthingResponse,
fetchErrorHandler?: () => void
) => AuthingGuardResponse = (
res: AuthingGuardResponse,
fetchErrorHandler
) => {
if (this.responseInterceptorMap.size === 0) return res

const interceptors = Array.from(this.responseInterceptorMap.values())

return interceptors.reduce((acc, cur) => cur(acc), res)
return interceptors.reduce((acc, cur) => cur(acc, fetchErrorHandler), res)
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/guard-core-v4/src/_utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ requestClient.baseUrl = ''
requestClient.setBaseUrl = (base: string) => {
requestClient.baseUrl = base.replace(/\/$/, '')
}
requestClient.getBaseUrl = (base: string) => {
return requestClient.baseUrl
}

const DEFAULT_LANG_HEADER = 'x-authing-lang'
const DEFAULT_TENANT_HEADER = 'x-authing-app-tenant-idåå'
Expand Down
5 changes: 4 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/en-us/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,8 @@
"successTip": "Password reset succeeded",
"backLogin": "Seconds will automatically jump to the login page"
},
"wecomScanLogin": "Enterprise WeChat scan code to log in"
"wecomScanLogin": "Enterprise WeChat scan code to log in",
"tenantCreateSuccess": "Created successfully, please contact the operator to configure the domain name",
"tenantAppDomain": "Tenant application domain:",
"tenantConsoleDomain": "Tenant backend domain:"
}
5 changes: 4 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/ja-jp/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,8 @@
"successTip": "パスワードのリセットに成功しました",
"backLogin": "秒ログインページが自動的にジャンプされます"
},
"wecomScanLogin": "エンタープライズ WeChat ログイン"
"wecomScanLogin": "エンタープライズ WeChat ログイン",
"tenantCreateSuccess": "作成に成功しました。ドメイン名を構成するにはオペレーターに連絡してください。",
"tenantAppDomain": "テナント アプリケーション ドメイン名:",
"tenantConsoleDomain": "テナントのバックエンド ドメイン名:"
}
5 changes: 4 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/zh-cn/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,8 @@
"successTip": "密码重置成功",
"backLogin": "秒后将自动跳转登录页"
},
"wecomScanLogin": "企业微信扫码登录"
"wecomScanLogin": "企业微信扫码登录",
"tenantCreateSuccess": "创建成功,请联系运营人员配置域名",
"tenantAppDomain": "租户应用域名:",
"tenantConsoleDomain": "租户后台域名:"
}
5 changes: 4 additions & 1 deletion packages/guard-core-v4/src/_utils/locales/zh-tw/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,8 @@
"successTip": "密碼重置成功",
"backLogin": "秒後將自動跳轉登入頁"
},
"wecomScanLogin": "企業微信掃碼登入"
"wecomScanLogin": "企業微信掃碼登入",
"tenantCreateSuccess": "建立成功,請聯絡營運人員配置網域名稱",
"tenantAppDomain": "租用戶應用網域:",
"tenantConsoleDomain": "租用戶後台網域:"
}
9 changes: 6 additions & 3 deletions packages/guard-core-v4/src/_utils/responseManagement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ export * from './interface'

export const errorCodeInterceptor: (
res: AuthingResponse<any>,
callBack: (code: CodeAction, res: AuthingResponse) => AuthingGuardResponse
) => AuthingResponse<any> = (res, callBack) => {
callBack: (code: CodeAction, res: AuthingResponse) => AuthingGuardResponse,
fetchErrorHandler?: () => void
) => AuthingResponse<any> = (res, callBack, fetchErrorHandler) => {
if (res.code === -1) {
message.error(i18n.t('common.timeout'))

return res
}
if (res.code === -2) {
message.error(i18n.t('common.fetchError'))
fetchErrorHandler
? fetchErrorHandler()
: message.error(i18n.t('common.fetchError'))

return res
}
Expand Down

0 comments on commit 8bea7df

Please sign in to comment.