forked from 77media/video-flow
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
/**
|
||
* 服务端配置工具函数
|
||
*/
|
||
|
||
import { post } from '@/api/request';
|
||
|
||
/**
|
||
* SSO配置接口
|
||
*/
|
||
export interface SSOConfig {
|
||
show: boolean;
|
||
provider: string;
|
||
displayName: string;
|
||
description: string;
|
||
}
|
||
|
||
/**
|
||
* 获取SSO配置
|
||
* @returns Promise<SSOConfig | null>
|
||
*/
|
||
export const getSSOConfig = async (): Promise<SSOConfig | null> => {
|
||
try {
|
||
console.log('🔍 开始获取SSO配置...');
|
||
const res = await post<any>(`/api/server-setting/find_by_code`, { code: 'sso_config' });
|
||
|
||
console.log('📋 SSO API响应:', res);
|
||
|
||
if (!res || res.code !== 0 || !res.successful || !res.data) {
|
||
console.warn('❌ Failed to fetch SSO config:', res);
|
||
return null;
|
||
}
|
||
|
||
// 新的数据格式:data直接包含id, code, value等字段
|
||
const { value } = res.data;
|
||
console.log('📝 SSO配置原始value:', value);
|
||
console.log('📝 value类型:', typeof value, 'value长度:', value?.length);
|
||
|
||
if (typeof value !== 'string' || value.length === 0) {
|
||
console.warn('❌ Invalid SSO config format:', value);
|
||
return null;
|
||
}
|
||
|
||
try {
|
||
const config: SSOConfig = JSON.parse(value);
|
||
console.log('✅ SSO配置解析成功:', config);
|
||
return config;
|
||
} catch (parseError) {
|
||
console.error('❌ Failed to parse SSO config:', parseError);
|
||
console.error('❌ 原始value:', JSON.stringify(value));
|
||
return null;
|
||
}
|
||
} catch (error) {
|
||
console.error('❌ Error fetching SSO config:', error);
|
||
return null;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 检查是否启用Google登录
|
||
* @returns Promise<boolean>
|
||
*/
|
||
export const isGoogleLoginEnabled = async (): Promise<boolean> => {
|
||
try {
|
||
console.log('🔍 检查Google登录是否启用...');
|
||
const config = await getSSOConfig();
|
||
console.log('📋 获得的配置:', config);
|
||
|
||
if (!config) {
|
||
console.log('❌ 没有获得配置,返回false');
|
||
return false;
|
||
}
|
||
|
||
const isEnabled = config?.show === true;
|
||
|
||
console.log('🔍 配置检查:', {
|
||
show: config?.show,
|
||
provider: config?.provider,
|
||
isEnabled,
|
||
finalResult: isEnabled
|
||
});
|
||
|
||
// 简化逻辑:只检查show字段,因为sso_config专门用于Google登录
|
||
return isEnabled;
|
||
} catch (error) {
|
||
console.error('❌ Error checking Google login status:', error);
|
||
return false; // 出错时默认不显示
|
||
}
|
||
};
|