feat: passkey wip
This commit is contained in:
parent
1599a8403f
commit
722e2c2afd
@ -215,13 +215,13 @@ const EditChannelModal = (props) => {
|
|||||||
onSuccess: (result) => {
|
onSuccess: (result) => {
|
||||||
// 验证成功后显示密钥
|
// 验证成功后显示密钥
|
||||||
if (result.success && result.data?.key) {
|
if (result.success && result.data?.key) {
|
||||||
|
showSuccess(t('密钥获取成功'));
|
||||||
setKeyDisplayState({
|
setKeyDisplayState({
|
||||||
showModal: true,
|
showModal: true,
|
||||||
keyData: result.data.key,
|
keyData: result.data.key,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
successMessage: t('密钥获取成功'),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重置密钥显示状态
|
// 重置密钥显示状态
|
||||||
@ -607,24 +607,15 @@ const EditChannelModal = (props) => {
|
|||||||
// 显示安全验证模态框并开始验证流程
|
// 显示安全验证模态框并开始验证流程
|
||||||
const handleShow2FAModal = async () => {
|
const handleShow2FAModal = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('=== handleShow2FAModal called ===');
|
|
||||||
console.log('channelId:', channelId);
|
|
||||||
console.log('startVerification function:', typeof startVerification);
|
|
||||||
|
|
||||||
// 测试模态框状态
|
|
||||||
console.log('Current modal state:', isModalVisible);
|
|
||||||
|
|
||||||
const apiCall = createApiCalls.viewChannelKey(channelId);
|
const apiCall = createApiCalls.viewChannelKey(channelId);
|
||||||
console.log('apiCall created:', typeof apiCall);
|
|
||||||
|
|
||||||
const result = await startVerification(apiCall, {
|
await startVerification(apiCall, {
|
||||||
title: t('查看渠道密钥'),
|
title: t('查看渠道密钥'),
|
||||||
description: t('为了保护账户安全,请验证您的身份。'),
|
description: t('为了保护账户安全,请验证您的身份。'),
|
||||||
preferredMethod: 'passkey', // 优先使用 Passkey
|
preferredMethod: 'passkey', // 优先使用 Passkey
|
||||||
});
|
});
|
||||||
console.log('startVerification result:', result);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('handleShow2FAModal error:', error);
|
console.error('Failed to start verification:', error);
|
||||||
showError(error.message || t('启动验证失败'));
|
showError(error.message || t('启动验证失败'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -81,17 +81,13 @@ export const useSecureVerification = ({
|
|||||||
|
|
||||||
// 开始验证流程
|
// 开始验证流程
|
||||||
const startVerification = useCallback(async (apiCall, options = {}) => {
|
const startVerification = useCallback(async (apiCall, options = {}) => {
|
||||||
console.log('startVerification called:', { apiCall, options });
|
|
||||||
const { preferredMethod, title, description } = options;
|
const { preferredMethod, title, description } = options;
|
||||||
|
|
||||||
// 检查验证方式
|
// 检查验证方式
|
||||||
console.log('Checking verification methods...');
|
|
||||||
const methods = await checkVerificationMethods();
|
const methods = await checkVerificationMethods();
|
||||||
console.log('Verification methods:', methods);
|
|
||||||
|
|
||||||
if (!methods.has2FA && !methods.hasPasskey) {
|
if (!methods.has2FA && !methods.hasPasskey) {
|
||||||
const errorMessage = t('您需要先启用两步验证或 Passkey 才能执行此操作');
|
const errorMessage = t('您需要先启用两步验证或 Passkey 才能执行此操作');
|
||||||
console.error('No verification methods available:', errorMessage);
|
|
||||||
showError(errorMessage);
|
showError(errorMessage);
|
||||||
onError?.(new Error(errorMessage));
|
onError?.(new Error(errorMessage));
|
||||||
return false;
|
return false;
|
||||||
@ -106,7 +102,6 @@ export const useSecureVerification = ({
|
|||||||
defaultMethod = '2fa';
|
defaultMethod = '2fa';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('Selected verification method:', defaultMethod);
|
|
||||||
|
|
||||||
setVerificationState(prev => ({
|
setVerificationState(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
@ -116,7 +111,6 @@ export const useSecureVerification = ({
|
|||||||
description
|
description
|
||||||
}));
|
}));
|
||||||
setIsModalVisible(true);
|
setIsModalVisible(true);
|
||||||
console.log('Modal should be visible now');
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}, [checkVerificationMethods, onError, t]);
|
}, [checkVerificationMethods, onError, t]);
|
||||||
|
|||||||
@ -34,24 +34,39 @@ export class SecureVerificationService {
|
|||||||
*/
|
*/
|
||||||
static async checkAvailableVerificationMethods() {
|
static async checkAvailableVerificationMethods() {
|
||||||
try {
|
try {
|
||||||
console.log('Checking user verification methods...');
|
|
||||||
const [twoFAResponse, passkeyResponse, passkeySupported] = await Promise.all([
|
const [twoFAResponse, passkeyResponse, passkeySupported] = await Promise.all([
|
||||||
API.get('/api/user/2fa/status'),
|
API.get('/api/user/2fa/status'),
|
||||||
API.get('/api/user/passkey'),
|
API.get('/api/user/passkey'),
|
||||||
isPasskeySupported()
|
isPasskeySupported()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
console.log('2FA response:', twoFAResponse);
|
console.log('=== DEBUGGING VERIFICATION METHODS ===');
|
||||||
console.log('Passkey response:', passkeyResponse);
|
console.log('2FA Response:', JSON.stringify(twoFAResponse, null, 2));
|
||||||
console.log('Passkey browser support:', passkeySupported);
|
console.log('Passkey Response:', JSON.stringify(passkeyResponse, null, 2));
|
||||||
|
|
||||||
|
const has2FA = twoFAResponse.data?.success && twoFAResponse.data?.data?.enabled === true;
|
||||||
|
const hasPasskey = passkeyResponse.data?.success && passkeyResponse.data?.data?.enabled === true;
|
||||||
|
|
||||||
|
console.log('has2FA calculation:', {
|
||||||
|
success: twoFAResponse.data?.success,
|
||||||
|
dataExists: !!twoFAResponse.data?.data,
|
||||||
|
enabled: twoFAResponse.data?.data?.enabled,
|
||||||
|
result: has2FA
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('hasPasskey calculation:', {
|
||||||
|
success: passkeyResponse.data?.success,
|
||||||
|
dataExists: !!passkeyResponse.data?.data,
|
||||||
|
enabled: passkeyResponse.data?.data?.enabled,
|
||||||
|
result: hasPasskey
|
||||||
|
});
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
has2FA: twoFAResponse.success && twoFAResponse.data?.enabled === true,
|
has2FA,
|
||||||
hasPasskey: passkeyResponse.success && (passkeyResponse.data?.enabled === true || passkeyResponse.data?.status === 'enabled' || passkeyResponse.data !== null),
|
hasPasskey,
|
||||||
passkeySupported
|
passkeySupported
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Final verification methods result:', result);
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to check verification methods:', error);
|
console.error('Failed to check verification methods:', error);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user