From 8370b23b65a1a30bc9d5246248cf47d4dcac7189 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Mon, 21 Feb 2022 12:21:49 +0300 Subject: [PATCH] Add Auth Way with disable anon auth. Fixed toolbar. --- Package.swift | 2 +- .../Interface/Auth/AuthController.swift | 15 ++++++++++----- .../Interface/Auth/AuthToolBarView.swift | 8 ++++---- Sources/SPProfiling/Models/AuthWay.swift | 7 +++++++ Sources/SPProfiling/SPProfiling.swift | 15 +++++++-------- Sources/SPProfiling/Services/Auth.swift | 4 +--- 6 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 Sources/SPProfiling/Models/AuthWay.swift diff --git a/Package.swift b/Package.swift index 5462ee7..bb041c8 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/ivanvorobei/SPAlert", .upToNextMajor(from: "4.2.0")), .package(url: "https://github.com/ivanvorobei/NativeUIKit", .upToNextMajor(from: "1.4.1")), - .package(url: "https://github.com/ivanvorobei/SPFirebase", .upToNextMajor(from: "1.0.6")), + .package(url: "https://github.com/ivanvorobei/SPFirebase", .upToNextMajor(from: "1.0.7")), .package(url: "https://github.com/sparrowcode/SPSafeSymbols", .upToNextMajor(from: "1.0.5")), .package(url: "https://github.com/kean/Nuke", .upToNextMajor(from: "10.7.1")) ], diff --git a/Sources/SPProfiling/Interface/Auth/AuthController.swift b/Sources/SPProfiling/Interface/Auth/AuthController.swift index e944644..894242e 100644 --- a/Sources/SPProfiling/Interface/Auth/AuthController.swift +++ b/Sources/SPProfiling/Interface/Auth/AuthController.swift @@ -102,12 +102,17 @@ open class AuthController: NativeOnboardingFeaturesController { @objc func updateSkipAuthButton() { let allowed: Bool = { - if ProfileModel.isAnonymous != nil { - // Any auth already isset. - // Not allowed anonymous auth. + switch SPProfiling.authWay { + case .onlyAuthed: return false - } else { - return true + case .anonymouslyAllowed: + if ProfileModel.isAnonymous != nil { + // Any auth already isset. + // Not allowed anonymous auth. + return false + } else { + return true + } } }() actionToolbarView.skipAuthButton.isHidden = !allowed diff --git a/Sources/SPProfiling/Interface/Auth/AuthToolBarView.swift b/Sources/SPProfiling/Interface/Auth/AuthToolBarView.swift index a629cfe..373abed 100644 --- a/Sources/SPProfiling/Interface/Auth/AuthToolBarView.swift +++ b/Sources/SPProfiling/Interface/Auth/AuthToolBarView.swift @@ -55,12 +55,12 @@ open class AuthToolBarView: NativeMimicrateToolBarView { open func setLoading(_ state: Bool) { if state { activityIndicatorView.startAnimating() - authButton.isHidden = true - skipAuthButton.isHidden = true + authButton.alpha = .zero + skipAuthButton.alpha = .zero } else { activityIndicatorView.stopAnimating() - authButton.isHidden = false - skipAuthButton.isHidden = false + authButton.alpha = 1 + skipAuthButton.alpha = 1 } } diff --git a/Sources/SPProfiling/Models/AuthWay.swift b/Sources/SPProfiling/Models/AuthWay.swift new file mode 100644 index 0000000..73b8258 --- /dev/null +++ b/Sources/SPProfiling/Models/AuthWay.swift @@ -0,0 +1,7 @@ +import Foundation + +public enum AuthWay { + + case onlyAuthed + case anonymouslyAllowed +} diff --git a/Sources/SPProfiling/SPProfiling.swift b/Sources/SPProfiling/SPProfiling.swift index c786800..0570d96 100644 --- a/Sources/SPProfiling/SPProfiling.swift +++ b/Sources/SPProfiling/SPProfiling.swift @@ -27,7 +27,9 @@ import SPFirebaseAuth public class SPProfiling { - public static func configure(firebaseOptions: FirebaseOptions) { + public static func configure(_ authWay: AuthWay, firebaseOptions: FirebaseOptions) { + + shared.authWay = authWay // Start Firebase SPFirebase.configure(with: firebaseOptions) @@ -89,13 +91,7 @@ public class SPProfiling { static func signOut(completion: @escaping (AuthError?)->Void) { Auth.signOut { error in - if let error = error { - completion(error) - } else { - signInAnonymously() { error in - completion(error) - } - } + completion(error) } } @@ -147,6 +143,7 @@ public class SPProfiling { // MARK: - Singltone + private var authWay: AuthWay = .anonymouslyAllowed private var authProcess: Bool = false private static let shared = SPProfiling() private init() {} @@ -157,4 +154,6 @@ public class SPProfiling { get { SPProfiling.shared.authProcess } set { SPProfiling.shared.authProcess = newValue } } + + public static var authWay: AuthWay { shared.authWay } } diff --git a/Sources/SPProfiling/Services/Auth.swift b/Sources/SPProfiling/Services/Auth.swift index 4f90371..e80f134 100644 --- a/Sources/SPProfiling/Services/Auth.swift +++ b/Sources/SPProfiling/Services/Auth.swift @@ -73,9 +73,7 @@ class Auth { if let error = error { completion(AuthError.convert(error)) } else { - signInAnonymously() { error in - completion(error) - } + completion(nil) } }) }