feat: verify Google OAuth code automatically after receipt
This commit is contained in:
1 parent
465eb5d0a4
commit
e927ac9506
3 files changed
+38
-30
No files matched your search
@@ -62,19 +62,49 @@ export function CloudAccountList() {
|
|||||||
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
|
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
|
||||||
const [authCode, setAuthCode] = useState('');
|
const [authCode, setAuthCode] = useState('');
|
||||||
|
|
||||||
|
const handleAddAccount = (codeVal?: string) => {
|
||||||
|
const codeToUse = codeVal || authCode;
|
||||||
|
if (!codeToUse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addMutation.mutate(
|
||||||
|
{ authCode: codeToUse },
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
setIsAddDialogOpen(false);
|
||||||
|
setAuthCode('');
|
||||||
|
toast({ title: t('cloud.toast.addSuccess') });
|
||||||
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
toast({
|
||||||
|
title: t('cloud.toast.addFailed.title'),
|
||||||
|
description: err.message,
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
// Listen for Google Auth Code
|
// Listen for Google Auth Code
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.electron?.onGoogleAuthCode) {
|
if (window.electron?.onGoogleAuthCode) {
|
||||||
|
console.log('[OAuth] Setting up auth code listener, dialog open:', isAddDialogOpen);
|
||||||
const cleanup = window.electron.onGoogleAuthCode((code) => {
|
const cleanup = window.electron.onGoogleAuthCode((code) => {
|
||||||
|
console.log('[OAuth] Received auth code via IPC:', code?.substring(0, 10) + '...');
|
||||||
setAuthCode(code);
|
setAuthCode(code);
|
||||||
// Auto submit if dialog is open
|
// Note: Auto-submit will be triggered by the authCode change effect below
|
||||||
if (isAddDialogOpen) {
|
|
||||||
handleAddAccount(code);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return cleanup;
|
return cleanup;
|
||||||
}
|
}
|
||||||
}, [isAddDialogOpen]);
|
}, []);
|
||||||
|
|
||||||
|
// Auto-submit when authCode is set and dialog is open
|
||||||
|
useEffect(() => {
|
||||||
|
if (authCode && isAddDialogOpen && !addMutation.isPending) {
|
||||||
|
console.log('[OAuth] Auto-submitting auth code');
|
||||||
|
handleAddAccount(authCode);
|
||||||
|
}
|
||||||
|
}, [authCode, isAddDialogOpen]);
|
||||||
|
|
||||||
// Batch Operations State
|
// Batch Operations State
|
||||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
||||||
@@ -176,28 +206,6 @@ export function CloudAccountList() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddAccount = (codeVal?: string) => {
|
|
||||||
const codeToUse = codeVal || authCode;
|
|
||||||
if (!codeToUse) return;
|
|
||||||
addMutation.mutate(
|
|
||||||
{ authCode: codeToUse },
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
|
||||||
setIsAddDialogOpen(false);
|
|
||||||
setAuthCode('');
|
|
||||||
toast({ title: t('cloud.toast.addSuccess') });
|
|
||||||
},
|
|
||||||
onError: (err) => {
|
|
||||||
toast({
|
|
||||||
title: t('cloud.toast.addFailed.title'),
|
|
||||||
description: err.message,
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const openAuthUrl = async () => {
|
const openAuthUrl = async () => {
|
||||||
try {
|
try {
|
||||||
await startAuthFlow();
|
await startAuthFlow();
|
||||||
|
|||||||
@@ -20,11 +20,13 @@ export class AuthServer {
|
|||||||
const error = url.searchParams.get('error');
|
const error = url.searchParams.get('error');
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
logger.info('AuthServer: Received authorization code');
|
logger.info(`AuthServer: Received authorization code: ${code.substring(0, 10)}...`);
|
||||||
|
|
||||||
// Send code to renderer
|
// Send code to renderer
|
||||||
if (ipcContext.mainWindow) {
|
if (ipcContext.mainWindow) {
|
||||||
|
logger.info('AuthServer: Sending code to renderer via IPC');
|
||||||
ipcContext.mainWindow.webContents.send('GOOGLE_AUTH_CODE', code);
|
ipcContext.mainWindow.webContents.send('GOOGLE_AUTH_CODE', code);
|
||||||
|
logger.info('AuthServer: Code sent successfully');
|
||||||
} else {
|
} else {
|
||||||
logger.error('AuthServer: Main window not found, cannot send code');
|
logger.error('AuthServer: Main window not found, cannot send code');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ export async function isProcessRunning(): Promise<boolean> {
|
|||||||
// Increased timeout to 4000ms to avoid flakiness with tasklist/wmic
|
// Increased timeout to 4000ms to avoid flakiness with tasklist/wmic
|
||||||
try {
|
try {
|
||||||
const { stdout } = await execAsync(command, { timeout: 4000 });
|
const { stdout } = await execAsync(command, { timeout: 4000 });
|
||||||
logger.debug(`Process check stdout: ${stdout.trim()}`);
|
|
||||||
|
|
||||||
if (platform === 'win32' || isWsl()) {
|
if (platform === 'win32' || isWsl()) {
|
||||||
return stdout.includes('Antigravity.exe');
|
return stdout.includes('Antigravity.exe');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user