feat: migrate app routes and business modules
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { resolveRuntimeMode } from '@/utils/runtime-config.js'
|
||||
import { AUTH_VERIFICATION_OPERATION } from '@/utils/auth/verification.js'
|
||||
import { session } from '@/utils/session.js'
|
||||
|
||||
export const requireRemoteAuth = () => {
|
||||
if (resolveRuntimeMode() !== 'remote') {
|
||||
const error = new Error('当前为本地预览模式,真实认证服务未启用')
|
||||
error.code = 'AUTH_REMOTE_REQUIRED'
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const assertAuthVerificationOperation = (operationCode) => {
|
||||
if (!Object.values(AUTH_VERIFICATION_OPERATION).includes(operationCode)) {
|
||||
throw new TypeError('认证动作不属于当前认证合同')
|
||||
}
|
||||
return operationCode
|
||||
}
|
||||
|
||||
export const assertValidToken = (validToken) => {
|
||||
if (typeof validToken !== 'string' || !validToken.trim()) {
|
||||
throw new TypeError('发送短信前必须取得有效的行为验证票据')
|
||||
}
|
||||
return validToken.trim()
|
||||
}
|
||||
|
||||
export const normalizeOptionalValidToken = (validToken) =>
|
||||
validToken === undefined ? undefined : assertValidToken(validToken)
|
||||
|
||||
export const assertPasswordHash = (passwordHash) => {
|
||||
if (typeof passwordHash !== 'string' || !/^[a-f0-9]{32}$/.test(passwordHash)) {
|
||||
throw new TypeError('密码摘要必须是 32 位小写 MD5')
|
||||
}
|
||||
return passwordHash
|
||||
}
|
||||
|
||||
export const saveLogin = (loginResult) => {
|
||||
const token = loginResult?.access_token
|
||||
if (!token) throw new Error('登录响应未包含会话令牌')
|
||||
session.saveToken(token)
|
||||
return loginResult
|
||||
}
|
||||
Reference in New Issue
Block a user