Skip to content

Commit

Permalink
Merge branch 'release/1.2.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mouredev committed Oct 7, 2021
2 parents efd2c77 + 3169d15 commit 38000c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Twitimer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@
"@executable_path/Frameworks",
);
MACH_O_TYPE = mh_execute;
MARKETING_VERSION = 1.2.1;
MARKETING_VERSION = 1.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.mouredev.Twitimer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -1142,7 +1142,7 @@
"@executable_path/Frameworks",
);
MACH_O_TYPE = mh_execute;
MARKETING_VERSION = 1.2.1;
MARKETING_VERSION = 1.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.mouredev.Twitimer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
22 changes: 11 additions & 11 deletions Twitimer/Model/Session/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,17 @@ final class Session {
}
}
}
}, failure: failure)
}, failure: failure, authFailure: failure)
}, failure: failure)
}

func revoke(success: @escaping () -> Void) {

if let accessToken = token?.accessToken {
TwitchService.shared.revoke(accessToken: accessToken) {
self.clear()
success()
self.clear(completion: success)
} failure: { (_) in
self.clear()
success()
self.clear(completion: success)
}
}
}
Expand Down Expand Up @@ -165,6 +163,8 @@ final class Session {

} failure: { (_) in
self.reloadUser(completion: completion)
} authFailure: { (_) in
self.clear(completion: completion)
}
}
}
Expand Down Expand Up @@ -417,7 +417,7 @@ final class Session {
}
}

private func clear() {
private func clear(completion: @escaping () -> Void) {

user?.followedUsers?.forEach({ (user) in
self.setupNotification(add: false, topic: user)
Expand All @@ -435,14 +435,14 @@ final class Session {
// Firebase Auth
do {
try Auth.auth().signOut()
firebaseAuth()
firebaseAuth(completion: completion)
} catch let error as NSError {
print ("Error signing out from Firebase: %@", error)
firebaseAuth()
firebaseAuth(completion: completion)
}
}

private func firebaseAuth(completion: (() -> Void)? = nil) {
private func firebaseAuth(completion: @escaping () -> Void) {

// Firebase auth anónima y permanente para poder realizar operaciones autenticadas contra Firebase
// TODO: Intentar integrar Twitch como sistema OAuth personalizado en Firebase
Expand All @@ -451,10 +451,10 @@ final class Session {
guard let user = authResult?.user else { return }
let uid = user.uid
UserDefaultsProvider.set(key: .firebaseAuthUid, value: uid)
completion?()
completion()
}
} else {
completion?()
completion()
}
}

Expand Down
19 changes: 12 additions & 7 deletions Twitimer/Provider/Services/Twitch/TwitchService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class TwitchService {
}
}

func user(retry: Bool = false, success: @escaping (_ user: User) -> Void, failure: @escaping (_ error: Error?) -> Void) {
func user(retry: Bool = false, success: @escaping (_ user: User) -> Void, failure: @escaping (_ error: Error?) -> Void, authFailure: @escaping (_ error: Error?) -> Void) {

guard let url = TwitchServiceAPI.user.url() else {
failure(nil)
Expand All @@ -102,12 +102,17 @@ final class TwitchService {

if let user = response.value?.data?.first {
success(user)
} else if response.response?.statusCode == self.kAuthErrorStatusCode, let token = Session.shared.token?.refreshToken, !retry {
self.refreshToken(refreshToken: token) {
// Retry
self.user(retry: true, success: success, failure: failure)
} failure: { (error) in
failure(error)
} else if response.response?.statusCode == self.kAuthErrorStatusCode {
if let token = Session.shared.token?.refreshToken, !retry {
self.refreshToken(refreshToken: token) {
// Retry
self.user(retry: true, success: success, failure: failure, authFailure: authFailure)
} failure: { (error) in
failure(error)
}
} else {
// Close session
authFailure(response.error)
}
} else {
failure(response.error)
Expand Down

0 comments on commit 38000c8

Please sign in to comment.