Files
supabase/apps/docs/lib/storage.ts
T
CharisandJoshen Lim 0e8ee2e890 feat: display api urls and keys instead of placeholders in docs (#19672)
**feat:** adds a component to display API endpoints and anon keys in docs if user is authenticated
makes the getting started UX smoother so users don't have to jump back and forth between docs and trying to find their keys in dashboard

**out of scope:** it would be very cool to display these directly in the code blocks. I looked into it and it would require quite a bit of work forking and modifying code-hike, so out of scope for now

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-01-09 15:00:31 -05:00

35 lines
1.0 KiB
TypeScript

export const LOCAL_STORAGE_KEYS = {
SAVED_ORG_PROJECT_BRANCH: 'docs.ui.user.selected.org_project_branch',
} as const
type LocalStorageKey = (typeof LOCAL_STORAGE_KEYS)[keyof typeof LOCAL_STORAGE_KEYS]
type StorageType = 'local' | 'session'
function getStorage(storageType: StorageType) {
return storageType === 'local' ? window.localStorage : window.sessionStorage
}
export function store(storageType: StorageType, key: LocalStorageKey, value: string) {
if (typeof window === 'undefined') return
const storage = getStorage(storageType)
try {
storage.setItem(key, value)
} catch {
console.error(`Failed to set storage item with key "${key}"`)
}
}
export function retrieve(storageType: StorageType, key: LocalStorageKey) {
if (typeof window === 'undefined') return
const storage = getStorage(storageType)
return storage.getItem(key)
}
export function remove(storageType: StorageType, key: LocalStorageKey) {
if (typeof window === 'undefined') return
const storage = getStorage(storageType)
return storage.removeItem(key)
}