docs: link, login, whoami commands

This commit is contained in:
Sebastian Rindom
2021-06-08 15:07:51 +02:00
parent 580c031fcf
commit d1ac092285
3 changed files with 20 additions and 4 deletions
+10 -4
View File
@@ -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&ltoken=${auth.user.id}`,
`${appHost}/local-link?lurl=http://localhost:9000&ltoken=${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&ltoken=${auth.user.id}`
)
})
},
@@ -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: {
@@ -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 =