Skip to content

Commit bedd71e

Browse files
doublefacedoubleface
authored andcommitted
feat: Add flag to force trusted device
1 parent ffd9b24 commit bedd71e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/@types/cozy-client.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ declare module 'cozy-client' {
119119
}
120120
subdomain: 'flat' | 'nested'
121121
locale: string
122+
flags?: Record<string, boolean, null>
122123
}
123124

124125
export const useClient = (): CozyClient => CozyClient as CozyClient

src/dataproxy/worker/data.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import CozyClient from 'cozy-client'
22
import Minilog from 'cozy-minilog'
33

44
import { LOCALSTORAGE_KEY_DELETING_DATA } from '@/consts'
5+
6+
import { ClientData } from '../common/DataProxyInterface'
57
const log = Minilog('👷‍♂️ [Worker utils]')
68

79
interface SessionInfo {
@@ -16,12 +18,22 @@ interface SessionResponse {
1618
}
1719

1820
export const queryIsTrustedDevice = async (
19-
client: CozyClient
21+
client: CozyClient,
22+
clientData: ClientData
2023
): Promise<boolean> => {
2124
const resp: SessionResponse = await client
2225
.getStackClient()
2326
.fetchJSON('GET', '/settings/sessions/current')
2427

28+
// Need to get the flag from clientData since cozy-flags are not fully initialized yet
29+
const flags = clientData.instanceOptions?.flags as
30+
| Record<string, boolean>
31+
| undefined
32+
33+
if (flags?.['dataproxy.force-trusted-device.enabled']) {
34+
return true
35+
}
36+
2537
const isLongRun = resp?.data?.attributes?.long_run
2638
const isUnDefined = isLongRun === undefined
2739

src/dataproxy/worker/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ const dataProxy: DataProxyWorker = {
132132

133133
// If the device is not trusted, we do not want to store any private data in Pouch
134134
// So use the PouchLink only if the user declared a trustful device for the given session
135-
const isTrustedDevice = await queryIsTrustedDevice(client)
135+
const isTrustedDevice = await queryIsTrustedDevice(client, clientData)
136+
log.debug(`Trusted Device: ${isTrustedDevice}`)
136137
// TODO: we should add the possibility to disable the pouchlink with a flag
137138
const links =
138139
isTrustedDevice && !clientData.useRemoteData

0 commit comments

Comments
 (0)