ActionCodeInfo.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. /// Manages information regarding action codes.
  16. @objc(FIRActionCodeInfo) open class ActionCodeInfo: NSObject {
  17. /// The operation being performed.
  18. @objc public let operation: ActionCodeOperation
  19. /// The email address to which the code was sent. The new email address in the case of
  20. /// `ActionCodeOperation.recoverEmail`.
  21. @objc public let email: String
  22. /// The email that is being recovered in the case of `ActionCodeOperation.recoverEmail`.
  23. @objc public let previousEmail: String?
  24. init(withOperation operation: ActionCodeOperation, email: String, newEmail: String?) {
  25. self.operation = operation
  26. if let newEmail {
  27. self.email = newEmail
  28. previousEmail = email
  29. } else {
  30. self.email = email
  31. previousEmail = nil
  32. }
  33. }
  34. /// Map a request type string to the corresponding operation type.
  35. /// - Parameter requestType: Request type returned in the server response.
  36. /// - Returns: The corresponding ActionCodeOperation for the supplied request type.
  37. class func actionCodeOperation(forRequestType requestType: String?) -> ActionCodeOperation {
  38. switch requestType {
  39. case "PASSWORD_RESET": return .passwordReset
  40. case "VERIFY_EMAIL": return .verifyEmail
  41. case "RECOVER_EMAIL": return .recoverEmail
  42. case "EMAIL_SIGNIN": return .emailLink
  43. case "VERIFY_AND_CHANGE_EMAIL": return .verifyAndChangeEmail
  44. case "REVERT_SECOND_FACTOR_ADDITION": return .revertSecondFactorAddition
  45. default: return .unknown
  46. }
  47. }
  48. }