Skip to content

Commit 26cdd4a

Browse files
author
Manus AI
committed
feat: Add resend-verification command for expired codes
Added new 'flb resend-verification' command to request a new verification code if the original expires or is lost. Features: - Interactive prompt for email or use -e flag - Supports --host parameter for self-hosted instances - Clear instructions on what to do after resending - Proper error handling for all response formats Usage: flb resend-verification -e email@example.com flb resend-verification -e email@example.com --host http://localhost:8000 This solves the problem of users being stuck if their verification code expires (1 hour expiration).
1 parent 0e44a57 commit 26cdd4a

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,73 @@ async function verifyCommand(options) {
928928
}
929929
}
930930

931+
// Command to resend verification code
932+
async function resendVerificationCommand(options) {
933+
console.log('\n📧 Resend Verification Code\n');
934+
935+
try {
936+
let email = options.email;
937+
const host = options.host || 'https://api.fleetbase.io';
938+
939+
// Prompt for email if not provided
940+
if (!email) {
941+
const answers = await prompt([
942+
{
943+
type: 'input',
944+
name: 'email',
945+
message: 'Email address:',
946+
validate: (value) => value ? true : 'Email is required'
947+
}
948+
]);
949+
email = answers.email;
950+
}
951+
952+
// Ensure host has protocol
953+
const apiHost = host.startsWith('http://') || host.startsWith('https://')
954+
? host
955+
: `https://${host}`;
956+
const resendApi = `${apiHost}/~registry/v1/developer-account/resend-verification`;
957+
958+
console.log('\nResending verification code...');
959+
960+
// Make API call to resend
961+
const response = await axios.post(resendApi, {
962+
email: email
963+
});
964+
965+
if (response.data.status === 'success') {
966+
console.log('\n✓ Verification code sent!');
967+
console.log('✓ Check your email for the new verification code.');
968+
console.log('\n👉 Once you receive it, run:');
969+
console.log(` flb verify -e ${email}` + (host !== 'https://api.fleetbase.io' ? ` --host ${host}` : ''));
970+
} else {
971+
console.error('\nFailed to resend:', response.data.message || 'Unknown error');
972+
process.exit(1);
973+
}
974+
} catch (error) {
975+
if (error.response) {
976+
const errorData = error.response.data;
977+
978+
// Handle different error response formats
979+
let errorMessage = 'Unknown error';
980+
if (errorData.message) {
981+
errorMessage = errorData.message;
982+
} else if (errorData.error) {
983+
errorMessage = errorData.error;
984+
} else if (errorData.errors && Array.isArray(errorData.errors)) {
985+
errorMessage = errorData.errors.join(', ');
986+
}
987+
988+
console.error('\nFailed to resend:', errorMessage);
989+
} else if (error.request) {
990+
console.error('\nFailed to resend: No response from server');
991+
} else {
992+
console.error('\nFailed to resend:', error.message);
993+
}
994+
process.exit(1);
995+
}
996+
}
997+
931998
// Command to install Fleetbase via Docker
932999
async function installFleetbaseCommand(options) {
9331000
const crypto = require('crypto');
@@ -1303,6 +1370,13 @@ program
13031370
.option('-h, --host <host>', 'API host with protocol (default: https://api.fleetbase.io)')
13041371
.action(verifyCommand);
13051372

1373+
program
1374+
.command('resend-verification')
1375+
.description('Resend verification code to your email')
1376+
.option('-e, --email <email>', 'Email address')
1377+
.option('-h, --host <host>', 'API host with protocol (default: https://api.fleetbase.io)')
1378+
.action(resendVerificationCommand);
1379+
13061380
program
13071381
.command('install-fleetbase')
13081382
.description('Install Fleetbase using Docker')

0 commit comments

Comments
 (0)