Skip to content

Commit

Permalink
logout() fucntion added and isSessionIdExists() modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Goel committed Sep 23, 2024
1 parent 44e222e commit ee3806c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/SingleFactorAuth/SingleFactorAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public class SingleFactorAuth {
return .init(privateKey: privKey, publicAddress: publicAddress)
}

public func isSessionIdExists() -> Bool {
if (sessionManager.getSessionID() != nil) && !(sessionManager.getSessionID()!.isEmpty) {
public func isSessionIdExists() async throws -> Bool {
let data = try await sessionManager.authorizeSession(origin: Bundle.main.bundleIdentifier ?? "single-factor-auth-swift")
if(data["privateKey"] as? String != nil && (sessionManager.getSessionID() != nil) && !(sessionManager.getSessionID()!.isEmpty)) {
return true
}
return false
Expand Down Expand Up @@ -93,4 +94,9 @@ public class SingleFactorAuth {
_ = try await sessionManager.createSession(data: sfaKey)
return sfaKey
}

public func logout() async throws -> Bool {
let logoutResult = try await sessionManager.invalidateSession()
return logoutResult
}
}
9 changes: 9 additions & 0 deletions Tests/SingleFactorAuthTests/SapphireMainnetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ final class SapphireMainnetTests: XCTestCase {
XCTAssertEqual(requiredPrivateKey, torusKey.getPrivateKey())
XCTAssertEqual("0xA92E2C756B5b2abABc127907b02D4707dc085612", torusKey.getPublicAddress())
}

func testLogout() async throws {
let idToken = try generateIdToken(email: TORUS_TEST_EMAIL)
let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken)
let _ = try await singleFactoreAuth.connect(loginParams: loginParams)

let result = try await singleFactoreAuth.logout()
XCTAssertEqual(result, true)
}
}

0 comments on commit ee3806c

Please sign in to comment.