ActionCodeInfo.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // TODO(Swift 6 Breaking): This type is immutable. Consider removing `open` at
  16. // breaking change so checked Sendable can be used.
  17. /// Manages information regarding action codes.
  18. @objc(FIRActionCodeInfo) open class ActionCodeInfo: NSObject, @unchecked Sendable {
  19. /// The operation being performed.
  20. @objc public let operation: ActionCodeOperation
  21. /// The email address to which the code was sent. The new email address in the case of
  22. /// `ActionCodeOperation.recoverEmail`.
  23. @objc public let email: String
  24. /// The email that is being recovered in the case of `ActionCodeOperation.recoverEmail`.
  25. @objc public let previousEmail: String?
  26. init(withOperation operation: ActionCodeOperation, email: String, newEmail: String?) {
  27. self.operation = operation
  28. if let newEmail {
  29. self.email = newEmail
  30. previousEmail = email
  31. } else {
  32. self.email = email
  33. previousEmail = nil
  34. }
  35. }
  36. /// Map a request type string to the corresponding operation type.
  37. /// - Parameter requestType: Request type returned in the server response.
  38. /// - Returns: The corresponding ActionCodeOperation for the supplied request type.
  39. class func actionCodeOperation(forRequestType requestType: String?) -> ActionCodeOperation {
  40. switch requestType {
  41. case "resetPassword": return .passwordReset
  42. case "verifyEmail": return .verifyEmail
  43. case "recoverEmail": return .recoverEmail
  44. case "signIn": return .emailLink
  45. case "verifyAndChangeEmail": return .verifyAndChangeEmail
  46. case "revertSecondFactorAddition": return .revertSecondFactorAddition
  47. default: return .unknown
  48. }
  49. }
  50. }