Skip to content

Commit

Permalink
fixes ios snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Mar 12, 2024
1 parent 623096a commit b74ca59
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
14 changes: 11 additions & 3 deletions v2/mfa/frontend-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,18 @@ import UIKit
import SuperTokensIOS

fileprivate class ViewController: UIViewController {
func isAllMFACompleted() {
if let accessTokenPayload: [String: Any] = try? SuperTokens.getAccessTokenPayloadSecurely(), let mfaObject: [String: Any] = accessTokenPayload["st-mfa"] as? [String: Any], let isMFACompleted: Boolean = mfaObject["v"] as? Boolean {
return isMFACompleted;
func isAllMFACompleted() -> Bool {
// Attempt to retrieve the access token payload securely
if let accessTokenPayload: [String: Any] = try? SuperTokens.getAccessTokenPayloadSecurely(),
// Extract the mfaObject from the accessTokenPayload
let mfaObject: [String: Any] = accessTokenPayload["st-mfa"] as? [String: Any],
// Determine if MFA has been completed
let isMFACompleted: Bool = mfaObject["v"] as? Bool {
// Return the MFA completion status
return isMFACompleted
}
// Return false if any of the unwrapping fails, indicating MFA completion status cannot be confirmed
return false
}
}
```
Expand Down
17 changes: 12 additions & 5 deletions v2/mfa/protect-routes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1052,11 +1052,18 @@ import SuperTokensIOS

fileprivate class ViewController: UIViewController {
func checkIfMFAIsCompleted() {
if let accessTokenPayload: [String: Any] = try? SuperTokens.getAccessTokenPayloadSecurely(), let mfaObject: [String: Any] = mfaObject["st-mfa"] as? [String: Any], let isMFACompleted: Bool = mfaObject["v"] as? Bool {
if isMFACompleted {
// All required factors for MFA have been completed
} else {
// You can check the `c` object from ["st-mfa"] prop to see which factors have been completed by the user
// Attempt to retrieve the access token payload securely
if let accessTokenPayload: [String: Any] = try? SuperTokens.getAccessTokenPayloadSecurely() {
// Extract the mfaObject from the accessTokenPayload
if let mfaObject: [String: Any] = accessTokenPayload["st-mfa"] as? [String: Any] {
// Determine if MFA has been completed
if let isMFACompleted: Bool = mfaObject["v"] as? Bool {
if isMFACompleted {
// All required factors for MFA have been completed
} else {
// You can check the `c` object from ["st-mfa"] prop to see which factors have been completed by the user
}
}
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions v2/mfa/step-up-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,15 @@ import SuperTokensIOS

fileprivate class ViewController: UIViewController {
func checkIfMFAIsCompleted() {
if let accessTokenPayload: [String: Any] = try? SuperTokens.getAccessTokenPayloadSecurely(), let mfaObject: [String: Any] = mfaObject["st-mfa"] as? [String: Any], let isMFACompleted: Bool = mfaObject["v"] as? Bool {
if let accessTokenPayload: [String: Any] = try? SuperTokens.getAccessTokenPayloadSecurely(), let mfaObject = accessTokenPayload["st-mfa"] as? [String: Any], let isMFACompleted = mfaObject["v"] as? Bool {
// Corrected the extraction of mfaObject from the accessTokenPayload
if isMFACompleted {
// All required factors for MFA have been completed
let mfaCompletedFactors: [String: Any] = mfaObject["c"] as? [String: Any];
if mfaCompletedFactors["totp"] == nil || mfaCompletedFactors["totp"] < (Date().timeIntervalSince1970 - 1000*60*5) {
// user has not finished TOTP MFA in the last 5 minutes
if let mfaCompletedFactors = mfaObject["c"] as? [String: Any], let totpTime = mfaCompletedFactors["totp"] as? Double {
// Corrected unwrapping of mfaCompletedFactors and casting of totpTime
if totpTime < (Date().timeIntervalSince1970 - 1000*60*5) {
// user has not finished TOTP MFA in the last 5 minutes
}
}
} else {
// You can check the `c` object from ["st-mfa"] prop to see which factors have been completed by the user
Expand Down

0 comments on commit b74ca59

Please sign in to comment.