Store API key locally

Store API key locally
0.0 0

#1

I am on the weather app and I understand that it is not a big deal if the world has access to my API key for this project, however, I would like to know if I can.

Code pen put out a suggestion that we can use local.storage- here is a snippet that aims to put data there and check if the data is stored. I can not access the data store from within code pen.

Any ideas how to make use of the browsers local data store?

var storage = (function() {
	var dataStore = "tests";
	var result;
	try {
		localStorage.setItem("dataStore", dataStore);
		result = localStorage.getItem(dataStore) == dataStore;
		
		return result + document.write(result, " ", window.localStorage.getItem(dataStore));
	} catch (exception) {
    return false + document.write("false");}
}());

#2

It doesn’t quite work that way on CodePen. Web storage is for storing [non-secure] data per origin, and strictly speaking it’s abusing it a bit storing API keys, but there is a workaround: https://blog.codepen.io/2017/08/10/window-prompt-localstorage-api-keys/


#3

HaHa @DanCouper - that code pen article was what got me started on this path. But when I started attempting to store and pull data I failed… hence the snippet to do the testing. Do I need to be in dev mode on Chrome to access the local storage perhaps?

Fellow campers have been using local storage for their pens:

LocalSettings = SettingsArray.toString();
			localStorage.setItem('SavedData', LocalSettings);