Always verify sessions before login

Also avoid auto-login if saved account is anonymous and invalid
as this results in fetching new account every time app is restarted
as long as the validation fails resulting in rate-limiting.

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-06-19 20:32:01 +05:30
parent 9b8e3cf9c4
commit 87af312f54
7 changed files with 19 additions and 4 deletions

View File

@@ -41,5 +41,6 @@ sealed class AuthState {
object SignedOut : AuthState() object SignedOut : AuthState()
object Valid : AuthState() object Valid : AuthState()
object Fetching: AuthState() object Fetching: AuthState()
object InValid: AuthState()
data class Status(val status: String?) : AuthState() data class Status(val status: String?) : AuthState()
} }

View File

@@ -91,7 +91,11 @@ class AccountActivity : BaseActivity() {
updateStatus(getString(R.string.requesting_new_session)) updateStatus(getString(R.string.requesting_new_session))
} }
AuthState.Valid -> { AuthState.Valid -> {
updateContents()
}
AuthState.InValid -> {
updateStatus(getString(R.string.failed_validating_account))
} }
AuthState.Available -> { AuthState.Available -> {
@@ -105,7 +109,7 @@ class AccountActivity : BaseActivity() {
} }
AuthState.SignedIn -> { AuthState.SignedIn -> {
updateContents() VM.observe()
} }
AuthState.SignedOut -> { AuthState.SignedOut -> {

View File

@@ -102,6 +102,11 @@ class SplashActivity : BaseActivity() {
moveToContent() moveToContent()
} }
AuthState.InValid -> {
updateStatus(getString(R.string.failed_validating_account))
updateActionLayout(true)
}
AuthState.Available -> { AuthState.Available -> {
updateStatus(getString(R.string.session_verifying)) updateStatus(getString(R.string.session_verifying))
updateActionLayout(false) updateActionLayout(false)
@@ -113,7 +118,7 @@ class SplashActivity : BaseActivity() {
} }
AuthState.SignedIn -> { AuthState.SignedIn -> {
moveToContent() VM.observe()
} }
AuthState.SignedOut -> { AuthState.SignedOut -> {

View File

@@ -215,7 +215,7 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
buildGoogleAuthData(email, aasToken) buildGoogleAuthData(email, aasToken)
} }
AccountType.ANONYMOUS -> { AccountType.ANONYMOUS -> {
buildAnonymousAuthData() liveData.postValue(AuthState.InValid)
} }
} }
} }

View File

@@ -156,7 +156,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_small" android:layout_marginHorizontal="@dimen/margin_large"
android:layout_marginVertical="@dimen/margin_small"
android:maxLines="2"
android:textAlignment="center" android:textAlignment="center"
tools:text="Status" /> tools:text="Status" />
</RelativeLayout> </RelativeLayout>

View File

@@ -64,6 +64,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/txt_title" android:layout_below="@id/txt_title"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginHorizontal="@dimen/margin_large"
android:maxLines="2"
android:textAlignment="center" android:textAlignment="center"
tools:text="Sign in first" /> tools:text="Sign in first" />
</RelativeLayout> </RelativeLayout>

View File

@@ -364,4 +364,5 @@
<string name="checking_for_updates">Checking for updates</string> <string name="checking_for_updates">Checking for updates</string>
<string name="pref_updates_check">Automated updates check</string> <string name="pref_updates_check">Automated updates check</string>
<string name="pref_updates_check_desc">Automatically check &amp; notify for new app updates periodically</string> <string name="pref_updates_check_desc">Automatically check &amp; notify for new app updates periodically</string>
<string name="failed_validating_account">Failed to validate account, might be rate-limited.\nPlease login again!</string>
</resources> </resources>