Applying the Authentication Using Kotlin: Part 2 results in warnings that block the application

 private fun login() {
        WebAuthProvider
            .login(account)
            .withScheme(getString(R.string.com_auth0_scheme))
            .withScope(getString(R.string.login_scopes))
            .withAudience(getString(R.string.login_audience, getString(R.string.com_auth0_domain)))
            .start(this, object : Callback<Credentials, AuthenticationException> {

                override fun onFailure(exception: AuthenticationException) {
                    showSnackBar(getString(R.string.login_failure_message, exception.getCode()))
                }

                override fun onSuccess(credentials: Credentials) {
                    cachedCredentials = credentials
                    showSnackBar(getString(R.string.login_success_message, credentials.accessToken))
                    updateUI()
                    showUserProfile()
                }
            })
    }

the error is : The corresponding parameter in the supertype ‘Callback’ is named ‘error’. This may cause problems when calling this function with named arguments.
Also :

 private fun showUserProfile() {
        // Guard against showing the profile when no user is logged in
        if (cachedCredentials == null) {
            return
        }

        val client = AuthenticationAPIClient(account)
        client
            .userInfo(cachedCredentials!!.accessToken!!)
            .start(object : Callback<UserProfile, AuthenticationException> {

                override fun onFailure(exception: AuthenticationException) {
                    showSnackBar(getString(R.string.general_failure_with_exception_code,
                        exception.getCode()))
                }

                override fun onSuccess(profile: UserProfile) {
                    cachedUserProfile = profile
                    updateUI()
                }

            })
    }

the warning is :Unnecessary non-null assertion (!!) on a non-null receiver of type String
I got these errors duplicated all over the code !
Thank you in advance for you help :grinning:

Hey there @hamzaoui.mohamedamin!

I believe these can safely be ignored, however you can get rid of the first error by simply using the error parameter name in your onFailure override to match the the Callback interface’s error as opposed to exception - For example:

override fun onFailure(error: AuthenticationException) {
     showSnackBar(getString(R.string.login_failure_message, error.getCode()))
                }

Regarding Unnecessary non-null assertion (!!) on a non-null receiver of type String - You should be able to remove the second non-null assertion and get rid of the warnings like so:

.userInfo(cachedCredentials!!.accessToken)

Hope this helps!

Thank you so much for you help, I kinda figured that out and it didn’t work there was even errors in layout so I after reading the article I downloaded the complete project! Thank you again for your help !

1 Like

No problem, happy to help! Glad you were able to get this sorted out :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.