Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9aa357c authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

App lounge: (issue_5168) modify MainActivity to clear user type if auth data...

App lounge: (issue_5168) modify MainActivity to clear user type if auth data is invalid and user type is not ANONYMOUS
parent 958cb182
Loading
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -149,15 +149,23 @@ class MainActivity : AppCompatActivity() {
                     * occur sequentially. Hence we run the suspend function directly
                     * inside a coroutine scope.
                     *
                     * ALso now destroyCredentials() no longer removes the user type
                     * (i.e. Google login or Anonymous). User type data is only removed on logout.
                     * New auth data is generated without prompting the user to choose Google login
                     * or Anonymous; which is the purpose of the issue filed above.
                     * Now destroyCredentials() no longer removes the user type from data store.
                     * (i.e. Google login or Anonymous).
                     * - If the type is User.ANONYMOUS then we do not prompt the user to login again,
                     *   we directly generate new auth data; which is the main Gitlab issue described above.
                     * - If not anonymous user, i.e. type is User.GOOGLE, in that case we clear
                     *   the USERTYPE value. This causes HomeFragment.onTosAccepted() to open
                     *   SignInFragment as we need fresh login from the user.
                     */
                    dataStoreModule.destroyCredentials()
                    dataStoreModule.userType.collect { user ->
                        Log.d(TAG, "Regenerating auth data for user type: $user")
                        if (!user.isBlank() && User.valueOf(user) == User.ANONYMOUS) {
                            Log.d(TAG, "Regenerating auth data for Anonymous user")
                            generateAuthDataBasedOnUserType(user)
                        } else {
                            Log.d(TAG, "Ask Google user to log in again")
                            dataStoreModule.clearUserType()
                        }
                    }
                } else {
                    Log.d(TAG, "Authentication data is valid!")