@@ -19,6 +19,7 @@ var hostSocket: String = ""
1919public var auth : Auth ?
2020var socketManager = SocketManager ( )
2121var runtime = Runtime ( )
22+ let timeoutLogin = 10
2223public typealias CallBackTypeConnection = ( String ) -> Void
2324var 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*/
11431147private 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 */
11711175private 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/**
0 commit comments