This commit is contained in:
seb
2026-07-31 05:54:13 +02:00
parent 6db7d4d75c
commit db8b192094
32 changed files with 100 additions and 2048 deletions

View File

@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { render, Box, Text, useApp, useInput } from 'ink';
import TextInput from 'ink-text-input';
import chalk from 'chalk';
@@ -48,6 +48,17 @@ const App = () => {
const [email, setEmail] = useState('');
const [message, setMessage] = useState('');
const [error, setError] = useState('');
const [emails, setEmails] = useState(null);
useEffect(() => {
if (mode !== MODES.LIST) {
return;
}
setEmails(null);
googleAuth.listAllowedEmails()
.then(setEmails)
.catch((err) => finish(false, err.message));
}, [mode]);
const finish = (success, text) => {
if (success) {
@@ -72,28 +83,28 @@ const App = () => {
setMode(action);
};
const handleAdd = () => {
const handleAdd = async () => {
try {
const trimmed = email.trim();
if (!trimmed || !trimmed.includes('@')) {
finish(false, 'Invalid email address');
return;
}
googleAuth.addAllowedEmail(trimmed);
await googleAuth.addAllowedEmail(trimmed);
finish(true, `Added ${trimmed.toLowerCase()} to google_auth`);
} catch (err) {
finish(false, err.message);
}
};
const handleRemove = () => {
const handleRemove = async () => {
try {
const trimmed = email.trim();
if (!trimmed) {
finish(false, 'Email is required');
return;
}
const removed = googleAuth.removeAllowedEmail(trimmed);
const removed = await googleAuth.removeAllowedEmail(trimmed);
finish(true, removed ? `Removed ${trimmed.toLowerCase()}` : `Email not found: ${trimmed}`);
} catch (err) {
finish(false, err.message);
@@ -107,7 +118,9 @@ const App = () => {
return e(Text, null, chalk.red(`Error: ${error}`));
}
if (mode === MODES.LIST) {
const emails = googleAuth.listAllowedEmails();
if (!emails) {
return e(Text, null, chalk.gray('Loading...'));
}
if (emails.length === 0) {
finish(true, 'No allowed emails in google_auth');
return e(Text, null, chalk.yellow('No allowed emails...'));