Skip to content

Commit

Permalink
fix: clear cached value after setting telemetry consent
Browse files Browse the repository at this point in the history
  • Loading branch information
juice49 authored and bjoerge committed Dec 11, 2023
1 parent cd555ca commit 18b2c26
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {type ConsentStatus} from '@sanity/telemetry'
import {ClientError, ServerError} from '@sanity/client'
import {type CliCommandAction} from '../../types'
import {debug} from '../../debug'
import {getUserConfig} from '../../util/getUserConfig'
import {TELEMETRY_CONSENT_CONFIG_KEY} from '../../util/createTelemetryStore'

type SettableConsentStatus = Extract<ConsentStatus, 'granted' | 'denied'>

Expand Down Expand Up @@ -99,6 +101,8 @@ function getMock(): Mock | undefined {

export function createSetTelemetryConsentAction(status: SettableConsentStatus): CliCommandAction {
return async function setTelemetryConsentAction(_, {apiClient, output, chalk}) {
const config = getUserConfig()

const client = apiClient({
requireUser: true,
requireProject: false,
Expand Down Expand Up @@ -126,6 +130,9 @@ export function createSetTelemetryConsentAction(status: SettableConsentStatus):
})
}

// Clear cached telemetry consent
config.delete(TELEMETRY_CONSENT_CONFIG_KEY)

output.print(chalk.green(resultMessages[status].success()))
} catch (err) {
err.message = resultMessages[status].failure(err?.responseBody?.message)
Expand Down

0 comments on commit 18b2c26

Please sign in to comment.