Skip to content

Commit

Permalink
Fix a bug where changing the authtoken would not work when app is run…
Browse files Browse the repository at this point in the history
…ning (#322)
  • Loading branch information
minsiam authored Apr 6, 2024
1 parent 94bfeee commit 99f498c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ let ngrokClient = null;
* @param {Object | string} opts
* @returns Promise<string>
*/

let authtoken;

async function connect(opts) {
const { tunnelOpts, globalOpts } = defaults(opts);
validate(globalOpts);

if (globalOpts.authtoken) {
if (authtoken !== globalOpts.authtoken) {
await kill();
}
authtoken = globalOpts.authtoken;
}
processUrl = await getProcess(globalOpts);
ngrokClient = new NgrokClient(processUrl);
return connectRetry(tunnelOpts);
Expand Down
12 changes: 12 additions & 0 deletions src/authtoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const { join } = require("path");

const { defaultDir, bin } = require("./constants");

const { killProcess } = require('./process');

let authtoken;

function consolidateTokenAndOpts(optsOrToken) {
const isOpts = typeof optsOrToken !== "string";
const opts = isOpts ? optsOrToken : {};
Expand All @@ -19,6 +23,7 @@ async function setAuthtoken(optsOrToken) {
command.push("--config=" + opts.configPath);
}


let dir = defaultDir;
if (opts.binPath) {
dir = opts.binPath(dir);
Expand All @@ -32,6 +37,13 @@ async function setAuthtoken(optsOrToken) {
process.stderr.once("data", () => reject(new Error("cant set authtoken")));
});

if (opts.authtoken) {
if (authtoken !== opts.authtoken) {
await killProcess();
}
authtoken = opts.authtoken;
}

try {
return await killed;
} finally {
Expand Down

0 comments on commit 99f498c

Please sign in to comment.