Skip to content

Commit

Permalink
fix: 解析 login_page_context
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoyafng committed Oct 11, 2024
1 parent b47fdf3 commit e94acc0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/guard-core-v4/src/_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,24 @@ export function deepMerge<T extends object = any>(
* @description 在托管页下上传query.login_page_context中指定的用户自定义字段进行补全(/oidc/auth发起的认证只会携带 login_page_context)
*/
export const getUserRegisterParams = () => {
let customData: any[] = []

const query = qs.parse(window.location.search, {
ignoreQueryPrefix: true
})
const loginPageContext: any = query.login_page_context

let loginPageContext: any = query.login_page_context

// 将 loginPageContext 从字符串转换为 JSON 对象
if (typeof loginPageContext === 'string') {
try {
loginPageContext = JSON.parse(loginPageContext)
} catch (error) {
console.error('Invalid JSON in login_page_context:', error)
return customData
}
}
const type = Object.prototype.toString.call(loginPageContext)
let customData = []
if (loginPageContext && type.includes('Array')) {
// 遍历数组 b,将每个对象的 key-value 转换为 { key: keyName, value: keyValue } 的形式
loginPageContext.forEach((item: { [x: string]: any }) => {
Expand Down

0 comments on commit e94acc0

Please sign in to comment.