8

I am creating Progressive-web-app application ,I want to store user information in local device. So, how can i do this.how can I store user login information,so that he does not have to login again and again

Palak Jain
  • 133
  • 1
  • 2
  • 5
  • Possible duplicate of [Local Storage vs Cookies](https://stackoverflow.com/questions/3220660/local-storage-vs-cookies) – Michael Shopsin Feb 15 '18 at 13:32
  • set the cookie expire time for longer period like 1 year or 2 year. So that user will be logged out after a longer period which will feel like they are always logged in. And if you are looking for store data like sqllite, you can use indexeddb. check this out article for more help on how tostore data - ujjwalguptaofficial.blogspot.in/2017/10/angular4-crud-operation-in-indexeddb.html – Ujjwal Kumar Gupta Feb 15 '18 at 14:49
  • A new interesting way to do this thanks to FileSystemAccesAPIs is to load the SQLite DB from the file system. I've discussed pros and cons here: https://anita-app.com/blog/articles/sqlite-in-a-pwa-with-file-system-access-api.html – don Dec 02 '21 at 07:08

2 Answers2

6

There's no SQLite for browsers, the closer you can achieve is using IndexedDB or localStorage.

I'm assuming you're using JWT or any other token authentication based tool/library, so just save that token and when the window load you'll check if the token is present and still valid, if so you can redirect the user to a desired page or let him navigate, the logic is up to you, but these are the two options you have.

Hope this helps.

Gabriel Barreto
  • 6,411
  • 2
  • 24
  • 47
  • Since 2022 there is now an official support (sqlite.wasm), and since 2012 multiple unofficial ones. – glautrou Mar 06 '23 at 16:07
1

You can use SQLite in modern WASM-capable browsers thanks to the official sqllite.wasm :

There is also a persistent storage option via:

  • local storage
  • session storage
  • OPFS (Origin-Private FileSystem)

You can even use it without WebAssembly since 2012.

glautrou
  • 3,140
  • 2
  • 29
  • 34