Skip to content

Commit

Permalink
Merge branch 'hotfix/logoutResetToAnonymous'
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAsterisco committed Apr 19, 2020
2 parents 74d19f9 + f11d31d commit 4a7a093
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 160 deletions.
20 changes: 4 additions & 16 deletions Example/RxFireAuth/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -16,14 +13,8 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 CocoaPods. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="RxFireAuth" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<rect key="frame" x="20" y="139.5" width="440" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand All @@ -33,9 +24,6 @@
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
Expand Down
36 changes: 35 additions & 1 deletion Example/RxFireAuth/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<scene sceneID="Nug-Yv-kp9">
<objects>
<tableViewController id="ctm-QS-frk" customClass="ViewController" customModule="RxFireAuth_Example" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" estimatedSectionHeaderHeight="-1" sectionFooterHeight="18" estimatedSectionFooterHeight="-1" id="oh8-fu-n4g">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" estimatedSectionHeaderHeight="-1" sectionFooterHeight="18" estimatedSectionFooterHeight="-1" id="oh8-fu-n4g">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
Expand Down Expand Up @@ -249,6 +249,39 @@
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="qlR-qY-KKn">
<rect key="frame" x="0.0" y="726.5" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="qlR-qY-KKn" id="q27-43-Ymq">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="Rcq-UE-Qbr">
<rect key="frame" x="20" y="0.0" width="335" height="44"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Reset Anonymous user after logout" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fu5-pU-8gN">
<rect key="frame" x="0.0" y="12" width="278" height="20.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mot-Jo-eYh">
<rect key="frame" x="286" y="6.5" width="51" height="31"/>
</switch>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="44" id="Lg7-24-mHV"/>
</constraints>
</stackView>
</subviews>
<constraints>
<constraint firstItem="Rcq-UE-Qbr" firstAttribute="top" secondItem="q27-43-Ymq" secondAttribute="top" id="4PU-rW-i69"/>
<constraint firstAttribute="trailing" secondItem="Rcq-UE-Qbr" secondAttribute="trailing" constant="20" symbolic="YES" id="cGu-zo-oVi"/>
<constraint firstAttribute="bottom" secondItem="Rcq-UE-Qbr" secondAttribute="bottom" id="iN0-nC-VDh"/>
<constraint firstItem="Rcq-UE-Qbr" firstAttribute="leading" secondItem="q27-43-Ymq" secondAttribute="leading" constant="20" symbolic="YES" id="zFY-xm-Cl3"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand All @@ -262,6 +295,7 @@
<outlet property="loginField" destination="hRm-F9-3g3" id="HaC-Kz-FKX"/>
<outlet property="nameField" destination="xXd-3v-zRi" id="igw-fT-jDW"/>
<outlet property="passwordField" destination="FMT-pY-asG" id="7Ay-uj-9lj"/>
<outlet property="resetAnononymousSwitch" destination="mot-Jo-eYh" id="ehW-PG-2Xf"/>
<outlet property="signInButton" destination="zK6-No-yaf" id="vsj-Ee-aWa"/>
<outlet property="signOutButton" destination="ftK-wu-fHt" id="ia4-38-0BB"/>
<outlet property="subtitleLabel" destination="8n1-U7-jzB" id="3NJ-4x-Yid"/>
Expand Down
6 changes: 3 additions & 3 deletions Example/RxFireAuth/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ViewController: UITableViewController {
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var updateProfileButton: UIButton!

@IBOutlet weak var resetAnononymousSwitch: UISwitch!

private var userManager: UserManagerType = UserManager()
private var disposeBag = DisposeBag()

Expand All @@ -50,12 +52,10 @@ class ViewController: UITableViewController {
}
self.subtitleLabel.text = "You are logged-in with \(user.email ?? "unknown")."
}
self.signOutButton.isEnabled = true
self.nameField.text = user.displayName
} else {
self.welcomeLabel.text = "Welcome!"
self.subtitleLabel.text = "You are not logged-in."
self.signOutButton.isEnabled = false
}
}).disposed(by: self.disposeBag)

Expand Down Expand Up @@ -123,7 +123,7 @@ class ViewController: UITableViewController {

@IBAction func signOut(sender: AnyObject) {
self.toggleProgress(true)
self.userManager.logout(resetToAnonymous: false)
self.userManager.logout(resetToAnonymous: self.resetAnononymousSwitch.isOn)
.subscribe(onCompleted: {
self.toggleProgress(false)
}, onError: self.show(error:))
Expand Down
79 changes: 64 additions & 15 deletions RxFireAuth/Classes/UserError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,38 @@ public enum UserError: LocalizedError {
case invalidEmail
/// The action would require to migrate the current user data to a new account.
case migrationRequired
/// The requested action cannot be performed because there is already an anonymous user logged-in.
case alreadyAnonymous
/// The specified user cannot be found.
case userNotFound
/// The specified user is disabled.
case userDisabled
/// The user token has expired.
case expiredToken
/// The specified password is invalid.
case wrongPassword
/// The specified credential is either expired or invalid.
case invalidCredential
/// The specified email is already in use in another account.
case emailAlreadyInUse
/// The specified password does not satisfy the basic security requirements.
case weakPassword(String?)
/// The requested action would target a different user than the one currently signed-in.
case wrongUser
/// The requested action requires a recent call to `self.confirmAuthentication(email:password:)`.
case authenticationConfirmationRequired
/// The specified provider is already linked with this user.
case providerAlreadyLinked
/// An error occurred while reaching Firebase servers.
case networkError
/// The requested operation is not enabled in Firebase Console.
case configurationError
/// The provided Firebase configuration is invalid.
case invalidConfiguration
/// An error occurred while attempting to access the keychain.
case keychainError(Error?)
/// An unknown error has occurred.
case unknown(Error?)

public var errorDescription: String? {
switch self {
Expand All @@ -35,21 +67,38 @@ public enum UserError: LocalizedError {
return "The provided email address is invalid."
case .migrationRequired:
return "Proceeding with this action requires confirmation to migrate data from a user account to another."
}
}

public var failureReason: String? {
switch self {
case .noUser:
return "There is no user currently logged-in."
case .invalidUpdate:
return "The update contains invalid data and cannot be performed."
case .alreadyLoggedIn:
return "The requested action can be performed only when there is an anonymous user or nobody logged-in."
case .invalidEmail:
return "The provided value is not a valid email address."
case .migrationRequired:
return "The requested action will result in deleting the currently logged-in user and replace it with another user account, hence the library is asking for confirmation that the caller will perform (or not) data migration."
case .alreadyAnonymous:
return "There is already an anonymous user logged-in."
case .userNotFound:
return "The specified user cannot be found."
case .networkError:
return "A network error occurred."
case .unknown(let error):
return error?.localizedDescription ?? "An unknown error occurred."
case .userDisabled:
return "The specified user is disabled."
case .expiredToken:
return "The credential stored on this device are no longer valid. Please re-authenticate."
case .wrongPassword:
return "The specified password is invalid."
case .invalidCredential:
return "The specified credential is invalid."
case .emailAlreadyInUse:
return "This email address is already registered with another account."
case .weakPassword(let reason):
return "The provided password does not satisfy the security requirements: \(reason ?? "please try again")."
case .wrongUser:
return "You are authenticating with a different user."
case .authenticationConfirmationRequired:
return "In order to perform this action, you'll have to confirm your credentials by authenticating again."
case .providerAlreadyLinked:
return "This login provider is already linked."
case .configurationError:
return "There is an error in your Firebase Console configuration."
case .invalidConfiguration:
return "There is an error in your app configuration."
case .keychainError(let error):
return "An error occurred while comunicating with the keychain: \(error?.localizedDescription ?? "unknown")"
}
}

Expand Down
Loading

0 comments on commit 4a7a093

Please sign in to comment.