From f58e2cdd05a63fd0cd93914d33df856fb8c60f44 Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:44:55 +0200 Subject: [PATCH] fix: clear state on logout --- Sources/SingleFactorAuth/SingleFactorAuth.swift | 2 ++ .../SapphireMainnetTests.swift | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Sources/SingleFactorAuth/SingleFactorAuth.swift b/Sources/SingleFactorAuth/SingleFactorAuth.swift index 5ec0d8b..ae951f5 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuth.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuth.swift @@ -131,5 +131,7 @@ public class SingleFactorAuth { public func logout() async throws { try await sessionManager.invalidateSession() + SessionManager.deleteSessionIdFromStorage() + self.state = nil } } diff --git a/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift b/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift index f9eb6cf..db4e5cb 100644 --- a/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift +++ b/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift @@ -1,8 +1,8 @@ import BigInt -import JWTKit -import XCTest import FetchNodeDetails +import JWTKit import SingleFactorAuth +import XCTest final class SapphireMainnetTests: XCTestCase { var singleFactoreAuth: SingleFactorAuth! @@ -46,12 +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 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) - try await singleFactoreAuth.logout() - } + try await singleFactoreAuth.logout() + XCTAssertNil(singleFactoreAuth.getSessionData()) + } }