docs: link, login, whoami commands
This commit is contained in:
@@ -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()
|
const tok = getToken()
|
||||||
if (!tok) {
|
if (!tok) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -31,6 +34,9 @@ module.exports = {
|
|||||||
process.exit(1)
|
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
|
const { data: auth } = await axios
|
||||||
.get(`${apiHost}/auth`, {
|
.get(`${apiHost}/auth`, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -42,6 +48,7 @@ module.exports = {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Create the user with the user id
|
||||||
if (!argv.skipLocalUser && auth.user) {
|
if (!argv.skipLocalUser && auth.user) {
|
||||||
const localCmd = resolveLocalCommand(`user`)
|
const localCmd = resolveLocalCommand(`user`)
|
||||||
await localCmd({
|
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(
|
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",
|
app: "browser",
|
||||||
wait: false,
|
wait: false,
|
||||||
@@ -63,7 +69,7 @@ module.exports = {
|
|||||||
bo.on("error", err => {
|
bo.on("error", err => {
|
||||||
console.warn(err)
|
console.warn(err)
|
||||||
console.log(
|
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}`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ const inquirer = require("inquirer")
|
|||||||
|
|
||||||
const { setToken } = require("../util/token-store")
|
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 = {
|
module.exports = {
|
||||||
login: async _ => {
|
login: async _ => {
|
||||||
const apiHost =
|
const apiHost =
|
||||||
@@ -54,6 +59,8 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
const auth = await fetchAuth()
|
const auth = await fetchAuth()
|
||||||
|
|
||||||
|
// This is kept alive for several seconds until the user has authenticated
|
||||||
|
// in the browser.
|
||||||
const { data: user } = await axios
|
const { data: user } = await axios
|
||||||
.get(`${apiHost}/auth`, {
|
.get(`${apiHost}/auth`, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
const axios = require("axios").default
|
const axios = require("axios").default
|
||||||
const { getToken } = require("../util/token-store")
|
const { getToken } = require("../util/token-store")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the locally logged in user.
|
||||||
|
*/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
whoami: async argv => {
|
whoami: async argv => {
|
||||||
const apiHost =
|
const apiHost =
|
||||||
|
|||||||
Reference in New Issue
Block a user