Skip to content

Commit

Permalink
Merge pull request #24 from MuShare/fix/refresh
Browse files Browse the repository at this point in the history
Return nil access token if not sign in
  • Loading branch information
lm2343635 authored Oct 23, 2020
2 parents cb6a82c + 7c51e6e commit a45b3ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ PODS:
- Kingfisher (5.15.2):
- Kingfisher/Core (= 5.15.2)
- Kingfisher/Core (5.15.2)
- PlutoSDK/Core (0.8.2):
- PlutoSDK/Core (0.8.3):
- Alamofire (~> 5)
- SwiftyJSON (~> 5)
- SwiftyUserDefaults (~> 5)
- PlutoSDK/Rx (0.8.2):
- PlutoSDK/Rx (0.8.3):
- PlutoSDK/Core (~> 0)
- RxCocoa (~> 5)
- RxCocoa (5.1.1):
Expand Down Expand Up @@ -40,7 +40,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Alamofire: 814429acc853c6c54ff123fc3d2ef66803823ce0
Kingfisher: 1f60394409c6b916ce31474bcf73fdde6f3b9a7b
PlutoSDK: d76147a692c4187826607b7db7a8a21d9908b4dd
PlutoSDK: 0b10a6d9c0289f0cecc6169d592a258cf4443eb7
RxCocoa: 32065309a38d29b5b0db858819b5bf9ef038b601
RxRelay: d77f7d771495f43c556cbc43eebd1bb54d01e8e9
RxSwift: 81470a2074fa8780320ea5fe4102807cb7118178
Expand All @@ -49,4 +49,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 2e5513e74b0475c9762d494f382ce658831b8a96

COCOAPODS: 1.9.3
COCOAPODS: 1.10.0
9 changes: 7 additions & 2 deletions Pluto/Classes/Core/Pluto+Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import SwiftyJSON
extension Pluto {

public func getAccessToken(isForceRefresh: Bool = false, completion: @escaping (String?) -> Void) {
guard state == .signin else {
completion(nil)
return
}
let expire = DefaultsManager.shared.expire
guard
!isForceRefresh,
Expand All @@ -46,6 +50,9 @@ extension Pluto {
refreshAccessTokenCompletions.append(completion)
return
}
refreshAccessTokenCompletions.append(completion)
isRefreshingAccessToken = true

guard let refreshToken = DefaultsManager.shared.refreshToken else {
refreshAccessTokenCompletions.forEach {
$0(nil)
Expand All @@ -54,8 +61,6 @@ extension Pluto {
isRefreshingAccessToken = false
return
}
refreshAccessTokenCompletions.append(completion)
isRefreshingAccessToken = true

AF.request(
url(from: "/v1/token/refresh"),
Expand Down
2 changes: 1 addition & 1 deletion PlutoSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'PlutoSDK'
s.version = '0.8.2'
s.version = '0.8.3'
s.summary = 'Swift SDK for Pluto login microservice.'

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit a45b3ab

Please sign in to comment.