longcelot-sheet-db
Version:
Google Sheets-backed staging database adapter for Node.js with schema-first design
51 lines • 2.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.authCommand = authCommand;
const chalk_1 = __importDefault(require("chalk"));
const oauth_1 = require("../../auth/oauth");
const oauthFlow_1 = require("../lib/oauthFlow");
const cliFiles_1 = require("../../utils/cliFiles");
/**
* Standalone entry point for the OAuth handshake that `sync` (and drop-table/drop-column/
* rename-column, via buildAdminAdapter) already trigger implicitly on first run. Existing
* behavior is untouched — this just gives that same flow its own command, so a project can be
* scaffolded (`init`) and authorized (`auth`) as two separate, explicit steps before the first
* `sync`, instead of authorization happening as a surprise mid-`sync`.
*/
async function authCommand(options) {
require('dotenv').config();
const requiredEnvVars = ['GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET', 'GOOGLE_REDIRECT_URI'];
for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
console.error(chalk_1.default.red(`❌ Missing environment variable: ${envVar}`));
console.log(chalk_1.default.gray(' Run `lsdb init` first, then fill in .env.'));
process.exit(1);
}
}
if (!options.force) {
const stored = (0, oauthFlow_1.readTokens)();
if (stored?.refresh_token) {
console.log(chalk_1.default.cyan(`ℹ Already authorized — ${cliFiles_1.TOKENS_FILENAME} has a stored refresh token.`));
console.log(chalk_1.default.gray(' Re-checking it still works (pass --force to re-authorize from scratch)...\n'));
}
}
const oauth = (0, oauth_1.createOAuthManager)({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
redirectUri: process.env.GOOGLE_REDIRECT_URI,
});
console.log(chalk_1.default.blue.bold('🔐 Authorizing lsdb with Google...\n'));
try {
await (0, oauthFlow_1.resolveTokens)(oauth, { force: options.force });
}
catch (err) {
console.error(chalk_1.default.red(`❌ Authentication failed: ${err}`));
process.exit(1);
}
console.log(chalk_1.default.green('✅ You are authenticated.'));
console.log(chalk_1.default.cyan('\nNext step: ') + chalk_1.default.white('lsdb sync\n'));
}
//# sourceMappingURL=auth.js.map