feat: passkey wip

This commit is contained in:
Seefs
2025-09-29 21:54:16 +08:00
parent dcf4336c75
commit 84cdd24116
3 changed files with 25 additions and 25 deletions

View File

@@ -215,13 +215,13 @@ const EditChannelModal = (props) => {
onSuccess: (result) => {
// 验证成功后显示密钥
if (result.success && result.data?.key) {
showSuccess(t('密钥获取成功'));
setKeyDisplayState({
showModal: true,
keyData: result.data.key,
});
}
},
successMessage: t('密钥获取成功'),
});
// 重置密钥显示状态
@@ -607,24 +607,15 @@ const EditChannelModal = (props) => {
// 显示安全验证模态框并开始验证流程
const handleShow2FAModal = async () => {
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);
console.log('apiCall created:', typeof apiCall);
const result = await startVerification(apiCall, {
await startVerification(apiCall, {
title: t('查看渠道密钥'),
description: t('为了保护账户安全,请验证您的身份。'),
preferredMethod: 'passkey', // 优先使用 Passkey
});
console.log('startVerification result:', result);
} catch (error) {
console.error('handleShow2FAModal error:', error);
console.error('Failed to start verification:', error);
showError(error.message || t('启动验证失败'));
}
};

View File

@@ -81,17 +81,13 @@ export const useSecureVerification = ({
// 开始验证流程
const startVerification = useCallback(async (apiCall, options = {}) => {
console.log('startVerification called:', { apiCall, options });
const { preferredMethod, title, description } = options;
// 检查验证方式
console.log('Checking verification methods...');
const methods = await checkVerificationMethods();
console.log('Verification methods:', methods);
if (!methods.has2FA && !methods.hasPasskey) {
const errorMessage = t('您需要先启用两步验证或 Passkey 才能执行此操作');
console.error('No verification methods available:', errorMessage);
showError(errorMessage);
onError?.(new Error(errorMessage));
return false;
@@ -106,7 +102,6 @@ export const useSecureVerification = ({
defaultMethod = '2fa';
}
}
console.log('Selected verification method:', defaultMethod);
setVerificationState(prev => ({
...prev,
@@ -116,7 +111,6 @@ export const useSecureVerification = ({
description
}));
setIsModalVisible(true);
console.log('Modal should be visible now');
return true;
}, [checkVerificationMethods, onError, t]);

View File

@@ -34,24 +34,39 @@ export class SecureVerificationService {
*/
static async checkAvailableVerificationMethods() {
try {
console.log('Checking user verification methods...');
const [twoFAResponse, passkeyResponse, passkeySupported] = await Promise.all([
API.get('/api/user/2fa/status'),
API.get('/api/user/passkey'),
isPasskeySupported()
]);
console.log('2FA response:', twoFAResponse);
console.log('Passkey response:', passkeyResponse);
console.log('Passkey browser support:', passkeySupported);
console.log('=== DEBUGGING VERIFICATION METHODS ===');
console.log('2FA Response:', JSON.stringify(twoFAResponse, null, 2));
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 = {
has2FA: twoFAResponse.success && twoFAResponse.data?.enabled === true,
hasPasskey: passkeyResponse.success && (passkeyResponse.data?.enabled === true || passkeyResponse.data?.status === 'enabled' || passkeyResponse.data !== null),
has2FA,
hasPasskey,
passkeySupported
};
console.log('Final verification methods result:', result);
return result;
} catch (error) {
console.error('Failed to check verification methods:', error);