Fix: Improve password verification and sync

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 15:01:56 +00:00
parent 15a4ca5e76
commit d44e47f177
2 changed files with 61 additions and 19 deletions

View File

@@ -5,7 +5,7 @@ import { Separator } from '@/components/ui/separator';
import { Badge } from '@/components/ui/badge';
import { useToast } from '@/hooks/use-toast';
import { useAuth } from '@/hooks/useAuth';
import { Shield, Key, Smartphone, Globe, Loader2 } from 'lucide-react';
import { Shield, Key, Smartphone, Globe, Loader2, RefreshCw } from 'lucide-react';
import { TOTPSetup } from '@/components/auth/TOTPSetup';
import { GoogleIcon } from '@/components/icons/GoogleIcon';
import { DiscordIcon } from '@/components/icons/DiscordIcon';
@@ -127,6 +127,17 @@ export function SecurityTab() {
// Refresh identities - should now include email provider after waiting in addPasswordToAccount
await loadIdentities();
// Check if password was actually verified
if (!hasPassword && addPasswordMode === 'standalone') {
// Password addition failed verification
toast({
title: 'Verification Failed',
description: 'Password was set but identity verification failed. Please refresh the page and check your Security settings.',
variant: 'destructive'
});
return; // Don't close dialog or clear provider
}
if (addPasswordMode === 'disconnect' && passwordSetupProvider) {
toast({
title: "Password Set",
@@ -146,6 +157,19 @@ export function SecurityTab() {
}
};
const handleRefreshIdentities = async () => {
setLoadingIdentities(true);
await loadIdentities();
setLoadingIdentities(false);
toast({
title: 'Identities Refreshed',
description: hasPassword
? 'Your password authentication is now active.'
: 'Identity status updated.',
});
};
const handleAddPassword = () => {
setAddPasswordMode('standalone');
setPasswordSetupProvider('google' as OAuthProvider);
@@ -206,22 +230,33 @@ export function SecurityTab() {
</CardDescription>
</CardHeader>
<CardContent>
{hasPassword ? (
<Button onClick={() => setPasswordDialogOpen(true)}>
Change Password
<div className="flex items-center gap-2">
{hasPassword ? (
<Button onClick={() => setPasswordDialogOpen(true)}>
Change Password
</Button>
) : (
<Button onClick={handleAddPassword} disabled={addingPassword}>
{addingPassword ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Adding Password...
</>
) : (
'Add Password'
)}
</Button>
)}
<Button
variant="ghost"
size="icon"
onClick={handleRefreshIdentities}
disabled={loadingIdentities}
title="Refresh identity status"
>
<RefreshCw className={`h-4 w-4 ${loadingIdentities ? 'animate-spin' : ''}`} />
</Button>
) : (
<Button onClick={handleAddPassword} disabled={addingPassword}>
{addingPassword ? (
<>
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
Adding Password...
</>
) : (
'Add Password'
)}
</Button>
)}
</div>
</CardContent>
</Card>
</div>