From d1ac092285766866f8eeb34e9a946d7685f45a80 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Tue, 8 Jun 2021 15:07:51 +0200 Subject: [PATCH] docs: link, login, whoami commands --- packages/medusa-cli/src/commands/link.js | 14 ++++++++++---- packages/medusa-cli/src/commands/login.js | 7 +++++++ packages/medusa-cli/src/commands/whoami.js | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/medusa-cli/src/commands/link.js b/packages/medusa-cli/src/commands/link.js index 6a8691e337..990842b6c5 100644 --- a/packages/medusa-cli/src/commands/link.js +++ b/packages/medusa-cli/src/commands/link.js @@ -23,6 +23,9 @@ module.exports = { } } + // Checks if there is already a token from a previous log in; this is + // necessary to redirect the customer to the page where local linking is + // done const tok = getToken() if (!tok) { console.log( @@ -31,6 +34,9 @@ module.exports = { process.exit(1) } + // Get the currenty logged in user; we will be using the Cloud user id to + // create a user in the local DB with the same user id; allowing you to + // authenticate to the local API. const { data: auth } = await axios .get(`${apiHost}/auth`, { headers: { @@ -42,6 +48,7 @@ module.exports = { process.exit(1) }) + // Create the user with the user id if (!argv.skipLocalUser && auth.user) { const localCmd = resolveLocalCommand(`user`) await localCmd({ @@ -51,10 +58,9 @@ module.exports = { }) } - console.log(auth.user) - + // This step sets the Cloud link by opening a browser const bo = await open( - `${appHost}/local-link?lurl=http://localhost:4000<oken=${auth.user.id}`, + `${appHost}/local-link?lurl=http://localhost:9000<oken=${auth.user.id}`, { app: "browser", wait: false, @@ -63,7 +69,7 @@ module.exports = { bo.on("error", err => { console.warn(err) console.log( - `Could not open browser go to: ${loginHost}${urls.browser_url}` + `Could not open browser go to: ${appHost}/local-link?lurl=http://localhost:9000<oken=${auth.user.id}` ) }) }, diff --git a/packages/medusa-cli/src/commands/login.js b/packages/medusa-cli/src/commands/login.js index a0c9a38bdb..1f383fc9e9 100644 --- a/packages/medusa-cli/src/commands/login.js +++ b/packages/medusa-cli/src/commands/login.js @@ -4,6 +4,11 @@ const inquirer = require("inquirer") const { setToken } = require("../util/token-store") +/** + * The login command allows the CLI to keep track of Cloud users; the command + * makes a cli-login request to the cloud server and keeps an open connection + * until the user has authenticated via the Medusa Cloud website. + */ module.exports = { login: async _ => { const apiHost = @@ -54,6 +59,8 @@ module.exports = { } const auth = await fetchAuth() + // This is kept alive for several seconds until the user has authenticated + // in the browser. const { data: user } = await axios .get(`${apiHost}/auth`, { headers: { diff --git a/packages/medusa-cli/src/commands/whoami.js b/packages/medusa-cli/src/commands/whoami.js index a01172435d..ab80d3b6f9 100644 --- a/packages/medusa-cli/src/commands/whoami.js +++ b/packages/medusa-cli/src/commands/whoami.js @@ -1,6 +1,9 @@ const axios = require("axios").default const { getToken } = require("../util/token-store") +/** + * Fetches the locally logged in user. + */ module.exports = { whoami: async argv => { const apiHost =