Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Fix: TouchID prompt on second install #273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Source/UI/Coordinators/PasswordCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import UIKit

private struct Constants {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add: private init() { } to avoid possibility to create an instance of Constants

static let BiometricsSecretsLabel = "com.schibsted.account.biometrics.secrets"
static let HasLoggedInBeforeSettingsKey = "com.schibsted.account.hasLoggedInBefore"

// Avoid the creation of an instance of Constants
private init() {}
}

class PasswordCoordinator: AuthenticationCoordinator, RouteHandler {
Expand Down Expand Up @@ -237,10 +241,11 @@ extension PasswordCoordinator {
self.navigationController.pushViewController(viewController, animated: true)
}
private func getPasswordFromKeychain(for identifier: Identifier, _ localizedReasonString: String) -> String? {
guard #available(iOS 11.3, *) else {
guard #available(iOS 11.3, *), let hasLoggedInBefore = Settings.value(forKey: Constants.HasLoggedInBeforeSettingsKey) as? Bool else {
// Fallback to passsword login
return nil
}

var query = [String: Any]()
query[kSecClass as String] = kSecClassGenericPassword
query[kSecReturnData as String] = kCFBooleanTrue
Expand All @@ -253,6 +258,7 @@ extension PasswordCoordinator {
if status == noErr, let qresult = queryResult as? Data, let password = String(data: qresult as Data, encoding: .utf8) {
return password
} else {
Settings.setValue(false, forKey: Constants.HasLoggedInBeforeSettingsKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to set it to false here? A missing value for the key Constants.HasLoggedInBeforeSettingsKey is treated the same as it having the value false in all cases, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but I prefer to be explicit here.

return nil
}
}
Expand Down Expand Up @@ -308,14 +314,14 @@ extension PasswordCoordinator {
dictionary[kSecValueData as String] = password.data(using: .utf8)! as CFData
dictionary[kSecAttrAccessControl as String] = accessControl

let hasLoggedInBeforeSettingsKey = "hasLoggedInBefore"
if let hasLoggedInBefore = Settings.value(forKey: hasLoggedInBeforeSettingsKey) as? Bool, hasLoggedInBefore {

if let hasLoggedInBefore = Settings.value(forKey: Constants.HasLoggedInBeforeSettingsKey) as? Bool, hasLoggedInBefore {
if self.configuration.useBiometrics {
SecItemAdd(dictionary as CFDictionary, nil)
}
completion()
} else {
Settings.setValue(true, forKey: hasLoggedInBeforeSettingsKey)
Settings.setValue(true, forKey: Constants.HasLoggedInBeforeSettingsKey)
if self.biometryType == .touchID {
let viewModel = PasswordViewModel(
identifier: identifier,
Expand Down