← Files RivetARCHIVED FILE
node_modules/rivet-design/dist/cli/browserSignIn.js
2.53 KB · Nov 5, 2026 · 12:09 UTC
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.signInThroughBrowser = void 0;
const AuthService_1 = require("../services/AuthService");
const browser_1 = require("./browser");
const envelope_1 = require("./envelope");
const SIGN_IN_WAIT_ENV = 'RIVET_SIGN_IN_WAIT_MS';
const DEFAULT_SIGN_IN_WAIT_MS = 45_000;
const SIGN_IN_POLL_INTERVAL_MS = 2_000;
const signInWaitMs = (env) => {
const parsed = Number.parseInt(env[SIGN_IN_WAIT_ENV] ?? '', 10);
return Number.isFinite(parsed) && parsed >= 0
? parsed
: DEFAULT_SIGN_IN_WAIT_MS;
};
const signInRequired = ({ command, io, authUrl, browser, }) => {
const message = browser?.action === 'launch_requested'
? `Rivet sign-in is open in the browser. Finish signing in there, then run \`rivet open\` again. If the browser did not open, use this link: ${authUrl}`
: `Sign in to Rivet in the browser with this link, then run \`rivet open\` again: ${authUrl}`;
io.writeProgress(message);
return (0, envelope_1.errorResult)(command, 'AUTH_REQUIRED', message, browser ? { browser } : undefined, (0, envelope_1.loginRecovery)(authUrl));
};
const signInThroughBrowser = async ({ command, io, isBrowserDisabled, env, editor, authService = new AuthService_1.AuthService(), launch, }) => {
const waitAttempts = isBrowserDisabled
? 0
: Math.floor(signInWaitMs(env) / SIGN_IN_POLL_INTERVAL_MS);
const isSignedIn = async (attempts) => (await authService.resumePendingLogin(attempts))?.success === true;
if (await isSignedIn(waitAttempts + 1))
return null;
const pending = authService.peekPendingLogin();
if (pending?.authUrl) {
return signInRequired({ command, io, authUrl: pending.authUrl });
}
const begun = await authService.beginGoogleLogin({
source: 'cli',
editor,
noBrowser: true,
});
if (!begun.started) {
return (0, envelope_1.errorResult)(command, 'AUTH_REQUIRED', `Authentication required. Rivet could not start browser sign-in: ${begun.error} Have the user run \`rivet login\` to sign in.`);
}
const browser = await (0, browser_1.requestBrowserOpen)({
url: begun.authUrl,
urlField: 'authUrl',
isBrowserDisabled,
io,
launch,
});
if (browser.action === 'launch_requested' && (await isSignedIn(waitAttempts)))
return null;
return signInRequired({ command, io, authUrl: begun.authUrl, browser });
};
exports.signInThroughBrowser = signInThroughBrowser;
//# sourceMappingURL=browserSignIn.js.mapSHA-256: ffbd80b5a8c86ff6da3bbab585696d84db40c5ff2e06626679f96428f93d97cf