SessionManager
open class SessionManager<T> where T : Decodable, T : Encodable
Session manager used to manage a user’s login status.
Subspec: Utility/SessionManager
let sessionManager = SessionManager<User>()
Given a Codable user object, the SessionManager will store the authentication token in the secure keychain and will store the user object into the user defaults for fast sign-in when the app is relaunched.
-
Authentication token of the current user.
Declaration
Swift
public var authToken: String? { get set } -
Current user of the application.
Declaration
Swift
public var user: T? { get set } -
Flag to determine if the user is logged in.
Declaration
Swift
public var isLoggedIn: Bool { get }
-
Keychain service used to access the keychain.
Declaration
Swift
private lazy var keychain: Keychain { get set } -
Bundle identifier of the app.
Declaration
Swift
private var bundleIdentifer: String { get } -
Authentication token keychain key.
Declaration
Swift
private var authTokenKeychainKey: String { get }
-
User key to access the user object from the UserDefaults.
Declaration
Swift
private let userKey: String
-
Default initializer. Reloads the user stored in the user defaults.
Declaration
Swift
public init()
-
Log out the current user.
Declaration
Swift
public func logOut()
-
Reloads the user that is stored in the user defaults.
Declaration
Swift
func loadStoredUser() -
Returns the string with the given identifer.
Declaration
Swift
func keychainString(_ identifier: String) -> String?Parameters
identifierKeychain id used to return the desired string.
Return Value
Optional string stored in the keychain.
-
Sets the value provided to the keychain.
Declaration
Swift
func setKeychainString(_ identifier: String, value: String?)Parameters
identifierKey identidier of the value.
valueString value to add to the keychain.
-
Removes the keychain string with the given parameter.
Declaration
Swift
func removeKeychainString(_ identifier: String)Parameters
identifierKey identifier to remove.
SessionManager Class Reference