Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter 3 Implement Promise

My CI app makes API call to third party Rest API server which will be consumed by the front end. At first, front end app will hit my CI app and which in turn will hit the third party LogInAPI(session valid for 15 mins), and after login, we need to hit subsequent API calls by passing the key(response of loginApi) in the header. So basically I need to hit loginAPI for every 15 minutes. I am trying angular promise kinda approach in my Codeigniter app don't know how to achieve it? what is the best way to do it to prevent the front end from receiving empty or session expired response?

like image 683
Psyche Genie Avatar asked Nov 08 '22 17:11

Psyche Genie


1 Answers

You do not need to keep refreshing that login. Create time stamp when You receive login from 3rd party API. Then pass it to back end on each request.

On the back end on each call from front end check time stamp, if it's expired do not do normal calls to API but first get the new login, then do requested calls.

As response to each front end call return also login info, so that front end gets's new credentials after renewal.

If credentials are app wide, then front end does not have to be aware of them at all. Just store credentials in some kind of storage (SQL DB, key value store, etc.), and do auto renewals when appropriate.

like image 107
przemo_li Avatar answered Nov 15 '22 07:11

przemo_li