diff --git a/README.md b/README.md index ba6dc3b..18c8a96 100644 --- a/README.md +++ b/README.md @@ -441,6 +441,22 @@ struct SelectRegionView: View { } ``` +## Logout User after application was uninstall + +If you want that user not to keep logged in after reinstalling an application please add the `keepUserAfterReinstall` property to the `Frontegg.plist` file: + +```xml + + + keepUserAfterReinstall + + ... + + +``` + +By default `keepUserAfterReinstall` is `true`. + ## Login with ASWebAuthenticationSession Starting from version 1.2.9, the Frontegg SDK has introduced support for ASWebAuthenticationSession, enhancing the login diff --git a/Sources/FronteggSwift/FronteggApp.swift b/Sources/FronteggSwift/FronteggApp.swift index cedbcd0..da60395 100644 --- a/Sources/FronteggSwift/FronteggApp.swift +++ b/Sources/FronteggSwift/FronteggApp.swift @@ -41,6 +41,10 @@ public class FronteggApp { self.handleLoginWithSocialLogin = bridgeOptions["loginWithSocialLogin"] ?? true self.handleLoginWithSSO = bridgeOptions["loginWithSSO"] ?? false + if FronteggApp.clearKeychain() { + self.credentialManager.clear() + } + /** lateInit used for react-native and ionic-capacitor initialization */ @@ -179,4 +183,16 @@ public class FronteggApp { logger.info("Frontegg Initialized succcessfully (region: \(regionKey))") } + private static func clearKeychain() -> Bool { + if PlistHelper.keepUserAfterReinstall() { + return false + } + + let userDefaults = UserDefaults.standard + if !userDefaults.bool(forKey: "IsFronteggFirstApplicationRun") { + userDefaults.set(true, forKey: "IsFronteggFirstApplicationRun") + return true + } + return false + } } diff --git a/Sources/FronteggSwift/utils/PlistHelper.swift b/Sources/FronteggSwift/utils/PlistHelper.swift index aeb037a..3dbb1d0 100644 --- a/Sources/FronteggSwift/utils/PlistHelper.swift +++ b/Sources/FronteggSwift/utils/PlistHelper.swift @@ -153,7 +153,16 @@ struct PlistHelper { return false } - + public static func keepUserAfterReinstall() -> Bool { + let bundle = Bundle.main; + if let path = bundle.path(forResource: "Frontegg", ofType: "plist"), + let values = NSDictionary(contentsOfFile: path) as? [String: Any], + let value = values["keepUserAfterReinstall"] as? Bool { + return value + } + return true + } + public static func getKeychainService() -> String { let bundle = Bundle.main; if let path = bundle.path(forResource: "Frontegg", ofType: "plist"), diff --git a/demo/demo/Frontegg.plist b/demo/demo/Frontegg.plist index 17623c9..aeffeca 100644 --- a/demo/demo/Frontegg.plist +++ b/demo/demo/Frontegg.plist @@ -2,6 +2,8 @@ + keepUserAfterReinstall + baseUrl https://auth.davidantoon.me clientId