removed IDToken encrption

This commit is contained in:
2026-03-09 12:19:55 +05:30
parent b5aa672b8e
commit 06d40b8e59
12 changed files with 120 additions and 131 deletions

View File

@@ -47,10 +47,9 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const [loading, setLoading] = useState(true)
// Initialize encryption keys on login
async function initializeEncryption(authUser: User, token: string) {
async function initializeEncryption(authUser: User) {
try {
const firebaseUID = authUser.uid
const firebaseIDToken = token
// Get or create salt
let salt = getSalt()
@@ -59,8 +58,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
saveSalt(salt)
}
// Derive master key from Firebase credentials
const derivedKey = await deriveSecretKey(firebaseUID, firebaseIDToken, salt)
// Derive master key from Firebase UID (stable across sessions)
const derivedKey = await deriveSecretKey(firebaseUID, salt)
// Check if device key exists
let deviceKey = await getDeviceKey()
@@ -110,13 +109,16 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const email = authUser.email!
// Initialize encryption before syncing user
await initializeEncryption(authUser, token)
await initializeEncryption(authUser)
// Try to get existing user
try {
console.log('[Auth] Fetching user by email:', email)
const existingUser = await getUserByEmail(email, token) as { id: string }
console.log('[Auth] Found existing user:', existingUser.id)
setUserId(existingUser.id)
} catch (error) {
console.warn('[Auth] User not found, registering...', error)
// User doesn't exist, register them
const newUser = await registerUser(
{
@@ -126,10 +128,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
},
token
) as { id: string }
console.log('[Auth] Registered new user:', newUser.id)
setUserId(newUser.id)
}
} catch (error) {
console.error('Error syncing user with database:', error)
console.error('[Auth] Error syncing user with database:', error)
throw error
}
}