Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle authentication when user is offline using Angular PWA?

I have an angular application with PWA. My main concern is to allow the user to use the app while offline without internet connection. The question is: how can I accomplish that with IdentityServer and OIDC ? I'm considering the following solution: Assuming I have a valid "Refresh Token", then as long as the internet connection is offline, I would consider the user as still authenticated. Of course, this means the user has already logged in while "online".

Any suggestions for handling "login" while still "offline". For example, Windows OS uses some kind of "local storage" to authentication users, even while they have no internet connection. Any suggestions, appreciated

like image 223
Jalal El-Shaer Avatar asked Feb 18 '19 13:02

Jalal El-Shaer


1 Answers

Assume that the user has an internet connection and login to the app:

  • Save the Refresh Token localstorage.setItem('resfreshToken', yourToken)
  • When the user opens the app check the localstorage.getItem('refereshToken')
  • If it's not null or empty then the user is authenticated.

As per my knowledge refresh tokens do not expire so that you can always use the refresh token to get a new token. So when the internet connection is back you can use the refresh token to request a new access token and submit the data changes.

like image 156
Balaj Khan Avatar answered Oct 08 '22 12:10

Balaj Khan