JavaScript local storage, storing data, sending data from login/sign up form
Hello guys, sorry to disturb you all; I've just learn some JS basics but I now need to learn how to store data so that my data persist like say I want to store a particular game score for a particular user, I need to know how to do that and also, transfer data during login or sign up. However, I don't know where to start or more precisely, I don't know what should I learn, can someone clarify it for me please, like on what should I read please
16 Replies
I'm also beginner I will give my answer but u can ask other people , Storing login or sign up details in localstorage is not good idea also it can store maximum of 5MB , So u can use database for this , since u r an beginner u can learn about storing values in db in backend cuz different user can different score so localstorage is not good
Maybe if u want to store like score , yeah local storage is better option for one player ( like only u r score )
U can get that localstorage value and update it
U can learn Localstorage in js from W3schools
localstorage is great for small pieces of data
indexed db is absolute hell to use and the api was made by the devil itself
think or localstorage as a dumb string->string map
you store a string based on a key, and you use the same key to get the string
thats it
you only have 5mb for localstorage, but you also have 5mb for sessionstorage
both work the same, but session storage vanishes once you close the browser (or tab, in incognito on chrome)
Awe why is indexed db such a pita? I just came across it a couple months ago and thought it was going to be the perfect solution for a site that blocks local storage but haven’t given it a go yet
imagine asynchronous before asynchronous
EVERYTHING is a callback
and to do anything, you need to work on the result of another callback
unless you use a library that simplifies all of this, and moves it all to promises, you will hate every single second of it
i tried to use it, but i very quickly gave up
Interesting , thank you for the heads up then. Was convinced it was the answer to all my problems 😆
sadly, it is 😦
if you want proper storage, you have 3 options:
- indexed db
- sqlite stored into localstorage
- sqlite stored as a file in chrome's storage
im not sure if firefox supports all the file stuff, but hope it does
The security rules block access to local storage unfortunately and there’s no place for environment variables to hold credentials for db connection. Someone had suggested using Cloudflare workers but I think that would have the same problem of needing env variables to connect to the worker that could then connect to a db
local storage isn't a place for database credentials
that's IN THE SERVER only
To clarify, I’m just saying since I’m blocked from using local storage I intended on trying indexedDB (to hold data, not credentials).
someone on another discord server suggested I use cloudflare workers to store the db credentials (postgres, supabase, mysql etc) and then the worker connect to the database that would hold the data (so using something like supabase instead of indexedDB or local storage). But then the problem persists that I have credentials to connect to the Worker and no server to hold environment variables. So back to indexedDB to hold the data
the easiest way is to create a token that you verify against a list of allowed tokens for a specific domain or ip
this way, if someone else uses the token, it won't work because the server rejects it
Interesting , so it would be a token on the Worker that only works from my IP ? Or is it a token on the database like Supabase so I can skip the Worker all together
it can be however you want, as long as that token it sent on all server requests
I would prefer to skip the Worker and just connect straight to supabase. Looking for resources on how to set it up. Are there any keywords I should specifically be searching ? Maybe restricted IP token or …?
you want to connect directly from the frontend to a database???
Need to connect from the Front-End to somewhere I can store nonsensitive data. Localstorage would've been perfect but the security rules prohibit it. So trying to figure out where else to save some data . Someone suggested I use a database like supabase and use cloudflare workers to protect those credentials. I'll prob give indexedDB a try since it's not a lot of data
then you have to connect to a backend
either a proper backend or firebase