I am writing an android app. Some of its functionalities require the user to be authenticated. I am planning to create an annotation like this:

fun commentOnTask(){

This annotation would check user status. If authenticated the function would be called; if not, it would navigate to login screen. After successful auth function will be called or it must navigate to previous screen.

Is it proper way, or there are better alternatives? Also I am thinking how would I test this after.


This is simple and could work. Another alternative:

Put this responsibility of authentication / authorization on an API gateway - This way you can reuse this kind of authentication / authorization logic across different applications.

You also free your application to be tested in isolation from the authentication / authorization logic, which is generally well tested if you are using gateway tools like AWS API gateway with OAuth providers like Auth0, Okta, etc.

  • I think the OP was referring to mobile UI implementation, but I agree that it's not clear from the question body. I just figured out looking at tags Sep 11 '20 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.