slight refactor of all the code, made it so that login and onboarding works, need to add system to validate connections to google photos + NAS before just blindly accepting

Added library home page and navigation bar at the bottom, using emojis as icon placeholders, album page also works.

elipses for settings and icon also work.
This commit is contained in:
bobbert committed 2026-02-21 13:52:28 +00:00
1 parent 37511780b7
commit c1d7139055
17 files changed
+1431 -10040

No files matched your search

+31 -54
View File
@@ -1,93 +1,70 @@
import * as Crypto from 'expo-crypto';
/**
* Credential Encryption Service
*
* Encrypts sensitive credentials before storing in database
* Uses base64 encoding (React Native compatible)
* For production, use a proper encryption library like react-native-aes-crypto
* Uses expo-crypto for password hashing (SHA-256)
* Uses base64 encoding for storing account data objects in the database
*/
class CredentialEncryption {
constructor() {
// Simple key for demo - in production, use proper key management
this.encryptionKey = 'photo-app-secret-key-2026';
}
/**
* Base64 encode a string (React Native compatible)
* Uses btoa which is available in React Native
* Hash a password using SHA-256 via expo-crypto
* Returns a hex digest string
*/
base64Encode(str) {
async hashPassword(password) {
try {
// btoa is available in React Native
return btoa(unescape(encodeURIComponent(str)));
if (!password) throw new Error('Password is required');
const digest = await Crypto.digestStringAsync(
Crypto.CryptoDigestAlgorithm.SHA256,
password
);
return digest;
} catch (error) {
console.error('Base64 encode error:', error);
throw new Error('Failed to encode data');
console.error('Password hashing error:', error);
throw new Error('Failed to hash password: ' + error.message);
}
}
/**
* Base64 decode a string (React Native compatible)
* Uses atob which is available in React Native
* Verify a password against a stored hash
*/
base64Decode(str) {
async verifyPassword(password, storedHash) {
try {
// atob is available in React Native
return decodeURIComponent(escape(atob(str)));
const hash = await this.hashPassword(password);
return hash === storedHash;
} catch (error) {
console.error('Base64 decode error:', error);
throw new Error('Failed to decode data');
console.error('Password verification error:', error);
throw new Error('Failed to verify password: ' + error.message);
}
}
/**
* Encrypt credentials before storing
* Converts object to JSON string, then base64 encodes it
* Encrypt an object for database storage (base64-encoded JSON)
*/
encrypt(data) {
try {
if (!data) {
throw new Error('No data provided to encrypt');
}
if (!data) throw new Error('No data provided to encrypt');
const jsonString = JSON.stringify(data);
const encoded = this.base64Encode(jsonString);
console.log('✓ Credentials encrypted successfully');
// btoa is available in React Native / Hermes
const encoded = btoa(unescape(encodeURIComponent(jsonString)));
return encoded;
} catch (error) {
console.error('Encryption error:', error);
throw new Error('Failed to encrypt credentials: ' + error.message);
throw new Error('Failed to encrypt data: ' + error.message);
}
}
/**
* Decrypt credentials after retrieving
* Base64 decodes, then parses JSON back to object
* Decrypt a base64-encoded JSON string back to an object
*/
decrypt(encryptedData) {
try {
if (!encryptedData) {
return null;
}
const jsonString = this.base64Decode(encryptedData);
const data = JSON.parse(jsonString);
console.log('✓ Credentials decrypted successfully');
return data;
if (!encryptedData) return null;
const jsonString = decodeURIComponent(escape(atob(encryptedData)));
return JSON.parse(jsonString);
} catch (error) {
console.error('Decryption error:', error);
throw new Error('Failed to decrypt credentials: ' + error.message);
}
}
/**
* Check if data is already encrypted (base64)
*/
isEncrypted(data) {
if (typeof data !== 'string') return false;
try {
this.base64Decode(data);
return true;
} catch {
return false;
throw new Error('Failed to decrypt data: ' + error.message);
}
}
}