Skip to content

Commit 6d8a4ca

Browse files
author
Cesar Oyarzun
committed
EXP-4173 change startAuth method, rename refresh token variable
1 parent 611f1d5 commit 6d8a4ca

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

ExpSwift/Classes/Exp.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var hostSocket: String = ""
1919
public var auth:Auth?
2020
var socketManager = SocketManager()
2121
var runtime = Runtime()
22+
let timeoutLogin = 10
2223
public typealias CallBackTypeConnection = (String) -> Void
2324
var authConnection = [String: CallBackTypeConnection]()
2425

@@ -1102,8 +1103,11 @@ public func getUser(_ host:String, token:String) -> Promise<User>{
11021103
@param options.
11031104
@return Promise<Auth>.
11041105
*/
1105-
func startAuth(_ auth:Auth) ->Promise<User>{
1106-
return getCurrentUser()
1106+
func startAuth(_ data:Auth) {
1107+
//set auth to context
1108+
auth = data
1109+
setTokenSDK(data)
1110+
refreshAuthToken(data)
11071111
}
11081112

11091113

@@ -1138,7 +1142,7 @@ public func stop(){
11381142

11391143

11401144
/**
1141-
Refresh Auth Token Recursive with Timeout
1145+
Refresh Auth Token Recursive with Auth
11421146
*/
11431147
private func refreshAuthToken(_ result:Auth){
11441148
after(interval: getTimeout(result)).then{ result -> Void in
@@ -1154,8 +1158,8 @@ private func refreshAuthToken(_ result:Auth){
11541158
/**
11551159
Refresh Auth Token Recursive with Timeout
11561160
*/
1157-
private func refreshAuthToken(_ expirationToken:String){
1158-
after(interval: getTimeout(Double(expirationToken)!)).then{ result -> Void in
1161+
private func refreshAuthToken(_ timeout:String){
1162+
after(interval: getTimeout(Double(timeout)!)).then{ result -> Void in
11591163
refreshToken().then{ result -> Void in
11601164
setTokenSDK(result)
11611165
expLogging("EXP refreshAuthToken: \(result.document)")
@@ -1169,10 +1173,13 @@ private func refreshAuthToken(_ expirationToken:String){
11691173
Get Time Out
11701174
*/
11711175
private func getTimeout(_ data:Auth) -> TimeInterval{
1172-
let expiration = data.get("expiration") as! Double
1173-
let startDate = Date(timeIntervalSince1970: expiration/1000)
1174-
let timeout = startDate.timeIntervalSince(Date())
1175-
return TimeInterval(Int64(timeout))
1176+
var timeoutVal:TimeInterval = TimeInterval(timeoutLogin);
1177+
if let expiration = data.get("expiration") as? Double{
1178+
let startDate = Date(timeIntervalSince1970: expiration/1000)
1179+
var timeout = startDate.timeIntervalSince(Date())
1180+
timeoutVal = TimeInterval(Int64(timeout))
1181+
}
1182+
return timeoutVal
11761183
}
11771184

11781185
/**

ExpSwift/Classes/Runtime.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,14 @@ open class Runtime{
163163
}
164164

165165
if let auth = options["auth"] as? Auth{
166-
startAuth(auth).then {(user: User) -> Void in
167-
self.initNetwork(auth)
168-
if self.enableSocket {
169-
socketManager.start_socket().then { (result: Bool) -> Void in
170-
if result{
171-
fulfill(true)
172-
}
166+
startAuth(auth)
167+
self.initNetwork(auth)
168+
if self.enableSocket {
169+
socketManager.start_socket().then { (result: Bool) -> Void in
170+
if result{
171+
fulfill(true)
173172
}
174173
}
175-
}.catch {error in
176-
reject(error)
177174
}
178175
}
179176
}

0 commit comments

Comments
 (0)