45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/*
|
|
* 안전 저장소 래퍼 — JWT는 expo-secure-store(네이티브 keychain/keystore)에 저장.
|
|
* 웹/미지원 플랫폼은 AsyncStorage로 폴백. 비밀번호는 절대 저장하지 않는다.
|
|
* "아이디 기억"(이메일)은 비민감 정보이므로 AsyncStorage 사용.
|
|
*/
|
|
import * as SecureStore from 'expo-secure-store';
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
import { Platform } from 'react-native';
|
|
|
|
const useSecure = Platform.OS !== 'web';
|
|
|
|
export async function secureSet(key: string, value: string): Promise<void> {
|
|
if (useSecure) {
|
|
await SecureStore.setItemAsync(key, value);
|
|
} else {
|
|
await AsyncStorage.setItem(key, value);
|
|
}
|
|
}
|
|
|
|
export async function secureGet(key: string): Promise<string | null> {
|
|
if (useSecure) {
|
|
return SecureStore.getItemAsync(key);
|
|
}
|
|
return AsyncStorage.getItem(key);
|
|
}
|
|
|
|
export async function secureDelete(key: string): Promise<void> {
|
|
if (useSecure) {
|
|
await SecureStore.deleteItemAsync(key);
|
|
} else {
|
|
await AsyncStorage.removeItem(key);
|
|
}
|
|
}
|
|
|
|
// 비민감 저장소 (아이디 기억 등)
|
|
export async function prefSet(key: string, value: string): Promise<void> {
|
|
await AsyncStorage.setItem(key, value);
|
|
}
|
|
export async function prefGet(key: string): Promise<string | null> {
|
|
return AsyncStorage.getItem(key);
|
|
}
|
|
export async function prefDelete(key: string): Promise<void> {
|
|
await AsyncStorage.removeItem(key);
|
|
}
|