tatsuyamoriguchi / Sleep-Tracer

1 stars 0 forks source link

Keychain error: -50 issue in static func doesAnyUserExist() → Bool in Authentication() #66

Closed tatsuyamoriguchi closed 1 month ago

tatsuyamoriguchi commented 1 month ago
    // Function to check if a user account already exists in Keychain
    static func doesAnyUserExist() -> Bool {
        // Define query parameters
        let query: [String: Any] = [
            kSecClass as String: kSecClassGenericPassword,
            kSecMatchLimit as String: kSecMatchLimitOne,
            kSecReturnAttributes as String: true
        ]

        // Try to fetch existing item from Keychain
        var result: CFTypeRef?
        let status = SecItemCopyMatching(query as CFDictionary, &result)
        print("doesAnyUserExist SecItemCopyMatching status: \(status)")

        // Check if user account exists or not
        if status == errSecSuccess {
            return true
        } else if status == errSecItemNotFound {
            return false
        } else {
            print("Keychain error: \(status)")
            return false
        }
    }