Files
bw-expo-app/lib/storage.ts
imeepos 7e3f94bae3 Initial commit: Expo app with Better Auth integration
- Complete Expo React Native app setup with TypeScript
- Better Auth authentication system integration
- Secure storage implementation for session tokens
- Authentication flow with login/logout functionality
- API client configuration for backend communication
- Responsive UI components with themed styling
- Expo Router navigation setup
- Development configuration and scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 10:32:52 +08:00

46 lines
1.3 KiB
TypeScript

import * as SecureStore from "expo-secure-store";
import { Platform } from "react-native";
interface Storage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
}
class WebStorage implements Storage {
getItem(key: string): string | null {
if (typeof window === "undefined") return null;
return window.localStorage.getItem(key);
}
setItem(key: string, value: string) {
if (typeof window === "undefined") return;
window.localStorage.setItem(key, value);
}
removeItem(key: string) {
if (typeof window === "undefined") return;
console.log(`[WebStorage] Removing key: ${key}`);
window.localStorage.removeItem(key);
console.log(`[WebStorage] Key removed. Verification:`, window.localStorage.getItem(key));
}
}
class NativeStorage implements Storage {
getItem(key: string): string | null {
return SecureStore.getItem(key);
}
setItem(key: string, value: string) {
SecureStore.setItem(key, value);
}
removeItem(key: string) {
console.log(`[NativeStorage] Removing key: ${key}`);
SecureStore.setItem(key, "");
console.log(`[NativeStorage] Key set to empty string`);
}
}
export const storage: Storage = Platform.OS === "web" ? new WebStorage() : new NativeStorage();