add checks to make sure we are on web (#879)

zio/stable
Ansh 2023-06-14 15:20:46 -07:00 committed by GitHub
parent 272ddeb7e2
commit 775b5e6578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,9 @@ export function useDebugHeaderSetting(agent: BskyAgent): [boolean, () => void] {
const [enabled, setEnabled] = useState<boolean>(isEnabled())
const toggle = useCallback(() => {
if (!isWeb || typeof window === 'undefined') {
return
}
if (!enabled) {
localStorage.setItem('set-header-x-appview-proxy', 'yes')
agent.api.xrpc.setHeader('x-appview-proxy', 'true')
@ -31,7 +34,7 @@ export function useDebugHeaderSetting(agent: BskyAgent): [boolean, () => void] {
}
export function setDebugHeader(agent: BskyAgent, enabled: boolean) {
if (!isWeb) {
if (!isWeb || typeof window === 'undefined') {
return
}
if (enabled) {
@ -53,5 +56,8 @@ export function applyDebugHeader(agent: BskyAgent) {
}
function isEnabled() {
if (!isWeb || typeof window === 'undefined') {
return false
}
return localStorage.getItem('set-header-x-appview-proxy') === 'yes'
}