Directive with ng-repeater for view responding to token authentication condition

I like to embed a directive (not controller) for each scope inside ng-repeater (e.g. news feed). If a user clicks ‘Like’ button, it will first post a token to a server, if the token is invalid, it will use ionic pop up to the screen for user login, else update the ‘Like’ button. I am not sure what’s the best way to go about this.
Sorry about this post is very open ended. This is a common use case for apps but it can be complicated to implement efficiently. Appreciate any pointer.

i would implement it in another way:

  1. send the “like” request anyway if a token is there
  2. if there is no token --> show login popup

1.1 --> request failes with 401 (invalid authorization --> like token is invalid, expired, …) --> show popup
So you only need to send 1 request and if that one errored with 401 --> show popup

1 Like