File size: 1,535 Bytes
68465df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {SETTINGS, engine} from "@mentra/engine"
// In-memory forced write below has no facade equivalent by design (it exists
// for the storage-failure fallback) — allowlisted raw store access.
import {useSettingsStore} from "@mentra/engine-host-internal"

function getAllowlistedEmails(): Set<string> {
  const raw = process.env.EXPO_PUBLIC_DEV_MODE_EMAILS ?? ""
  return new Set(
    raw
      .split(",")
      .map((e: string) => e.trim().toLowerCase())
      .filter(Boolean),
  )
}

export function isDevModeAllowlisted(email: string | null | undefined): boolean {
  if (!email) return false
  return getAllowlistedEmails().has(email.toLowerCase().trim())
}

/** Enable dev_mode for allowlisted accounts (syncs to cloud user settings). */
export async function ensureDevModeForUser(email: string | null | undefined): Promise<void> {
  if (!isDevModeAllowlisted(email)) return

  const current = engine.settings.get(SETTINGS.debug_mode.key)
  if (current === true) return

  console.log("DEV: Auto-enabling debug_mode for allowlisted user")
  const result = await engine.settings.set(SETTINGS.debug_mode.key, true)
  if (result.is_error()) {
    console.warn("DEV: Failed to persist debug_mode:", result.error)
    // Still enable locally so Developer settings is reachable this session.
    // (V1 server write removed; settings are local-first post-cutover.)
    useSettingsStore.setState((state) => ({
      settings: {...state.settings, [SETTINGS.debug_mode.key]: true},
    }))
  }
}