Skip to content

Commit

Permalink
Add Auth Way with disable anon auth. Fixed toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Feb 21, 2022
1 parent 8d73d5b commit 8370b23
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
],
Expand Down
15 changes: 10 additions & 5 deletions Sources/SPProfiling/Interface/Auth/AuthController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Sources/SPProfiling/Interface/Auth/AuthToolBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/SPProfiling/Models/AuthWay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

public enum AuthWay {

case onlyAuthed
case anonymouslyAllowed
}
15 changes: 7 additions & 8 deletions Sources/SPProfiling/SPProfiling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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() {}
Expand All @@ -157,4 +154,6 @@ public class SPProfiling {
get { SPProfiling.shared.authProcess }
set { SPProfiling.shared.authProcess = newValue }
}

public static var authWay: AuthWay { shared.authWay }
}
4 changes: 1 addition & 3 deletions Sources/SPProfiling/Services/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class Auth {
if let error = error {
completion(AuthError.convert(error))
} else {
signInAnonymously() { error in
completion(error)
}
completion(nil)
}
})
}
Expand Down

0 comments on commit 8370b23

Please sign in to comment.