Skip to content

Commit

Permalink
feat(harvest): HandleOAuthResponse can deal with cozy-data from DOM
Browse files Browse the repository at this point in the history
to get domain and token value
  • Loading branch information
JF-Cozy committed May 18, 2022
1 parent 7a3ffdd commit 7c6ac1a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/cozy-harvest-lib/src/helpers/oauth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import uuid from 'uuid/v4'
import get from 'lodash/get'

import * as konnectors from './konnectors'
import CozyClient from 'cozy-client'
import CozyRealtime from 'cozy-realtime'
import get from 'lodash/get'
import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset'

import * as konnectors from './konnectors'

export const OAUTH_REALTIME_CHANNEL = 'oauth-popup'

Expand Down Expand Up @@ -55,10 +57,12 @@ export const handleOAuthResponse = (options = {}) => {
if (!realtime) {
let client = options.client
if (!client) {
const root = document.querySelector('[role=application]')
const domain = readCozyDataFromDOM('domain')
const token = readCozyDataFromDOM('token')

client = new CozyClient({
uri: `${window.location.protocol}//${root.dataset.cozyDomain}`,
token: root.dataset.cozyToken
uri: `${window.location.protocol}//${domain}`,
token: token
})
}
realtime = new CozyRealtime({ client })
Expand Down

0 comments on commit 7c6ac1a

Please sign in to comment.