GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode-mobile/shared/storage/connection-password.ts at main · drpr/opencode-mobile

Expand file tree

/

connection-password.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
60 lines (52 loc) · 2.51 KB
/

connection-password.ts

Copy path

File metadata and controls

60 lines (52 loc) · 2.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as SecureStore from 'expo-secure-store';
import { Platform } from 'react-native';
import { getConnectTestSecret, setConnectTestSecret } from '@/shared/storage/cloud-link';
import type { OpencodeConnectionSettings } from '@/shared/protocol/opencode/client';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { SETTINGS_STORAGE_KEY } from '@/shared/storage/keys';
import { stripServerUrlCredentials } from '@/shared/contracts/server-url';
const CONNECTION_PASSWORD_STORAGE_KEY = 'opencode-mobile.connection-password';
type StoredConnectionSettings = Omit<OpencodeConnectionSettings, 'password' | 'headers' | 'certificate'>;
// Everything that must stay out of AsyncStorage: credentials, gateway headers
// and custom certificates. Each lives under its own protected store.
export function withoutConnectionSecrets(settings: OpencodeConnectionSettings): StoredConnectionSettings {
const { password: _password, headers: _headers, certificate: _certificate, ...storedSettings } = settings;
return { ...storedSettings, serverUrl: stripServerUrlCredentials(storedSettings.serverUrl) };
}
export async function getConnectionPassword() {
if (Platform.OS === 'web') {
return getConnectTestSecret(CONNECTION_PASSWORD_STORAGE_KEY);
}
const password = await SecureStore.getItemAsync(CONNECTION_PASSWORD_STORAGE_KEY);
if (password) {
return password;
}
try {
const raw = await AsyncStorage.getItem(SETTINGS_STORAGE_KEY);
if (!raw) {
return '';
}
const settings = JSON.parse(raw) as Record<string, unknown>;
if (typeof settings.password !== 'string') {
return '';
}
const { password: legacyPassword, ...storedSettings } = settings;
if (typeof storedSettings.serverUrl === 'string') storedSettings.serverUrl = stripServerUrlCredentials(storedSettings.serverUrl);
await SecureStore.setItemAsync(CONNECTION_PASSWORD_STORAGE_KEY, legacyPassword);
await AsyncStorage.setItem(SETTINGS_STORAGE_KEY, JSON.stringify(storedSettings));
return legacyPassword;
} catch {
return '';
}
}
export async function saveConnectionPassword(password: string, background = false) {
if (Platform.OS === 'web') {
setConnectTestSecret(CONNECTION_PASSWORD_STORAGE_KEY, password);
return;
}
if (password) {
await SecureStore.setItemAsync(CONNECTION_PASSWORD_STORAGE_KEY, password, background ? { keychainAccessible: SecureStore.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY } : undefined);
return;
}
await SecureStore.deleteItemAsync(CONNECTION_PASSWORD_STORAGE_KEY);
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.