Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Mark CLI admin as setup; add login fallback UI

Juan Denisc160536c0a3a
diff --git a/backend/cli.py b/backend/cli.py
index 13deb2e2..52fa31db 100644
--- a/backend/cli.py
+++ b/backend/cli.py
@@ -78,6 +78,10 @@ def create_admin(email, username, password):
db.session.add(user)
db.session.commit()
+ # Mark setup as complete so the UI doesn't show the setup wizard
+ from app.services.settings_service import SettingsService
+ SettingsService.complete_setup(user_id=user.id)
+
click.echo(click.style(f'Admin user "{username}" created successfully!', fg='green'))
diff --git a/frontend/src/components/setup/SetupStepAccount.jsx b/frontend/src/components/setup/SetupStepAccount.jsx
index e580376b..b34c4706 100644
--- a/frontend/src/components/setup/SetupStepAccount.jsx
+++ b/frontend/src/components/setup/SetupStepAccount.jsx
@@ -9,9 +9,12 @@ const SetupStepAccount = ({ onComplete }) => {
const [confirmPassword, setConfirmPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
- const { register } = useAuth();
+ const { register, login, registrationEnabled } = useAuth();
- async function handleSubmit(e) {
+ // If users already exist (e.g. admin created via CLI), show login form instead
+ const showLogin = !registrationEnabled;
+
+ async function handleRegister(e) {
e.preventDefault();
setError('');
@@ -37,6 +40,80 @@ const SetupStepAccount = ({ onComplete }) => {
}
}
+ async function handleLogin(e) {
+ e.preventDefault();
+ setError('');
+ setLoading(true);
+
+ try {
+ await login(email, password);
+ onComplete({ email, username: email });
+ } catch (err) {
+ setError(err.message || 'Failed to sign in');
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ if (showLogin) {
+ return (
+ <div className="wizard-step">
+ <h2 className="wizard-step-title">Sign In</h2>
+ <p className="wizard-step-description">
+ An admin account already exists. Sign in to continue setup.
+ </p>
+
+ <div className="wizard-info-banner">
+ <div className="wizard-info-icon">
+ <Info size={20} />
+ </div>
+ <p>
+ It looks like an admin account was created via the CLI.
+ Sign in with those credentials to finish setting up your server.
+ </p>
+ </div>
+
+ {error && <div className="error-message">{error}</div>}
+
+ <form onSubmit={handleLogin}>
+ <div className="form-group">
+ <label htmlFor="email">Email</label>
+ <input
+ type="email"
+ id="email"
+ value={email}
+ onChange={(e) => setEmail(e.target.value)}
+ placeholder="[email protected]"
+ required
+ autoFocus
+ />
+ </div>
+
+ <div className="form-group">
+ <label htmlFor="password">Password</label>
+ <input
+ type="password"
+ id="password"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ placeholder="Enter your password"
+ required
+ />
+ </div>
+
+ <button
+ type="submit"
+ className="btn-wizard-next"
+ disabled={loading}
+ style={{ width: '100%', justifyContent: 'center' }}
+ >
+ {loading ? 'Signing in...' : 'Sign In & Continue'}
+ </button>
+ </form>
+ </div>
+ );
+ }
+
return (
<div className="wizard-step">
<h2 className="wizard-step-title">Create Admin Account</h2>
@@ -57,7 +134,7 @@ const SetupStepAccount = ({ onComplete }) => {
{error && <div className="error-message">{error}</div>}
- <form onSubmit={handleSubmit}>
+ <form onSubmit={handleRegister}>
<div className="form-group">
<label htmlFor="email">Admin Email</label>
<input
diff --git a/frontend/src/contexts/AuthContext.jsx b/frontend/src/contexts/AuthContext.jsx
index 460c5456..9df7814f 100644
--- a/frontend/src/contexts/AuthContext.jsx
+++ b/frontend/src/contexts/AuthContext.jsx
@@ -20,7 +20,7 @@ export function AuthProvider({ children }) {
checkSetupStatus();
}, []);
- async function checkSetupStatus() {
+ async function checkSetupStatus(retries = 3) {
try {
const status = await api.getSetupStatus();
setSetupStatus({
@@ -37,7 +37,18 @@ export function AuthProvider({ children }) {
await checkAuth();
} catch (error) {
console.error('Setup status check failed:', error);
- // Fallback to checking auth directly
+ // Backend may not be ready yet — retry before falling back
+ if (retries > 0) {
+ await new Promise(r => setTimeout(r, 2000));
+ return checkSetupStatus(retries - 1);
+ }
+ // Exhausted retries — assume fresh install so user isn't locked out
+ setSetupStatus(prev => ({
+ ...prev,
+ needsSetup: true,
+ registrationEnabled: true,
+ checked: true
+ }));
await checkAuth();
}
}