How to use the cozy-client.default function in cozy-client

To help you get started, we’ve selected a few cozy-client 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 cozy / cozy-bar / src / index.jsx View on Github external
// Force public mode in `/public` URLs
  if (!isPublic && /^\/public/.test(window.location.pathname)) {
    isPublic = true
  }

  if (!cozyClient) {
    const ccURI = cozyURL || getDefaultStackURL(isPublic)
    const ccToken = token || getDefaultToken(isPublic)
    const ccOptions = {
      uri: ccURI,
      token: ccToken
    }
    // eslint-disable-next-line no-console
    console.warn('Automatically made cozyClient. Options: ', ccOptions)
    const CozyClient = require('cozy-client').default
    cozyClient = new CozyClient({})
    // TODO, initializing CozyClient with a uri/token should automatically
    // call login(). Without login(), CozyClient.isLogged is false.
    cozyClient.login(ccOptions)
  }

  // store
  const getOrCreateStore = require('lib/store').default
  const reduxStore = getOrCreateStore()

  reduxStore.dispatch(setInfos(appName, appNamePrefix, appSlug))
  stack.init({
    cozyClient,
    onCreate: data => reduxStore.dispatch(onRealtimeCreate(data)),
    onDelete: data => reduxStore.dispatch(onRealtimeDelete(data))
  })
  if (lang) {
github cozy / cozy.github.io / en / ach / libs / tasks.js View on Github external
async getClient(domain) {
    if (!this.clientPerDomain[domain]) {
      const token = await createToken(domain, this.doctypes)
      const client = new CozyClient({
        uri: 'https://' + domain,
        token
      })
      this.clientPerDomain[domain] = client
    }
    return this.clientPerDomain[domain]
  }