How to use the @vtex/api.ID function in @vtex/api

To help you get started, we’ve selected a few @vtex/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vtex / toolbelt / src / modules / auth / login.js View on Github external
import log from '../../logger'
import endpoint from '../../endpoint'
import {version} from '../../../package.json'
import {
  getLogin,
  saveToken,
  saveLogin,
  getAccount,
  saveAccount,
  getWorkspace,
  saveWorkspace,
} from '../../conf'

let workspaces = safeGetClient('workspaces')

const vtexid = new ID(endpoint('vtexid'), {
  authToken: 'abc123',
  userAgent: `Toolbelt/${version}`,
})
const [account, login, workspace] = [getAccount(), getLogin(), getWorkspace()]

function safeGetClient (client) {
  const clients = '../../clients.js'
  try {
    delete require.cache[require.resolve(clients)]
    return require(clients)[client]
  } catch (e) {}
}

function isVtexUser (email) {
  return email.indexOf('@vtex.com') >= 0
}