Skip to content

Commit

Permalink
Update TagoDeploy service URLs in login command
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuscardosodeveloper committed Aug 23, 2024
1 parent 1567abe commit 57cb130
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { writeToken } from "../lib/token";
/**
* @description Set the TagoIO deploy URL.
*/
async function setTagoDeployUrl() {
async function setTagoDeployUrl(): Promise<{ urlAPI: string; urlSSE: string } | undefined> {
const { tagoDeployUrl } = await prompts({
message: "Do you want to pass on the tagoDeploy URL?",
type: "confirm",
Expand All @@ -20,13 +20,15 @@ async function setTagoDeployUrl() {
}

const { urlAPI } = await prompts({ type: "text", name: "urlAPI", message: "Set the URL for the API service: " });
if (urlAPI) {
process.env.TAGOIO_API = urlAPI;
if (!urlAPI) {
return;
}

console.info(process.env.TAGOIO_API);
const urlSSE = urlAPI.replace("https://api.", "https://sse.").replace(".tago-io.net", ".tago-io.net/events");
process.env.TAGOIO_API = urlAPI;
process.env.TAGOIO_SSE = urlSSE;

return urlAPI;
return { urlAPI, urlSSE };
}

function writeCustomToken(environment: string, token: string) {
Expand All @@ -39,6 +41,7 @@ interface LoginOptions {
password?: string;
token?: string;
tagoDeployUrl?: string;
tagoDeploySse?: string;
}

/**
Expand Down Expand Up @@ -91,8 +94,9 @@ async function loginWithEmailPassword(email: string, password: string) {
}

async function tagoLogin(environment: string, options: LoginOptions) {
const tagoDeployUrl = await setTagoDeployUrl();
options.tagoDeployUrl = tagoDeployUrl;
const tagoDeploy = await setTagoDeployUrl();
options.tagoDeployUrl = tagoDeploy?.urlAPI;
options.tagoDeploySse = tagoDeploy?.urlSSE;

if (options.token) {
return writeCustomToken(environment, options.token);
Expand Down
9 changes: 3 additions & 6 deletions src/commands/start-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ async function createEnvironmentToken(environment: string) {
}
infoMSG(`You can create a token by running: ${highlightMSG("tagoio login")}`);

const options = { token: undefined, tagoDeployUrl: undefined };
const options = { token: undefined, tagoDeployUrl: undefined, tagoDeploySse: undefined };
await tagoLogin(environment, options);

return { profileToken: options.token, tagoDeployUrl: options?.tagoDeployUrl };
return { profileToken: options.token, tagoDeployUrl: options?.tagoDeployUrl, tagoDeploySse: options?.tagoDeploySse };
}

/**
Expand Down Expand Up @@ -155,6 +155,7 @@ async function startConfig(environment: string, { token }: ConfigOptions) {
const data = await createEnvironmentToken(environment);
token = data?.profileToken;
configFile.tagoDeployUrl = data?.tagoDeployUrl || "";
configFile.tagoDeploySse = data?.tagoDeploySse || "";
}
} else {
writeToken(token, environment);
Expand All @@ -169,10 +170,6 @@ async function startConfig(environment: string, { token }: ConfigOptions) {
configFile.buildPath = await promptTextToEnter(`Enter the path of your ${kleur.cyan("building")} folder (typescript): `, "./build");
}

if (!configFile.tagoDeploySse) {
configFile.tagoDeploySse = "";
}

// Return if token is not found
if (!token) {
return;
Expand Down

0 comments on commit 57cb130

Please sign in to comment.