Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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) {
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]
}