# localStorage.getItem returns null

**URL:** <https://forum.wixstudio.com/t/localstorage-getitem-returns-null/53284>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [October 25, 2023, 2:09pm UTC](https://forum.wixstudio.com/t/localstorage-getitem-returns-null/53284 "2023-10-25T14:09:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user682](https://avatars.discourse-cdn.com/v4/letter/u/ad7895/32.png) [@user682](https://forum.wixstudio.com/u/user682)\
**Post date:** [October 25, 2023, 2:09pm UTC](https://forum.wixstudio.com/t/localstorage-getitem-returns-null/53284/1 "2023-10-25T14:09:07Z")

</div>

**Discussion:**  
localStorage.getItem returns null

**What are you trying to achieve:**  
I’m trying to retrieve user data from the local storage

**Additional information:**  
I’ve manually set the `user` variable inside the local storage and I’m trying to retrieve it in the code:

```javascript
import { local as storage } from 'wix-storage';

$w.onReady(function () {
	let user = storage.getItem('user');
	console.log('user', user); // null
	if (user) {
	 	try {
	 		user = JSON.parse(user);
	 		if (!user || !user.parent) {
	 			// todo redirect to
 			        console.log('redirect to login page as well')
	 		} else {
	 			console.log('User data: ', user);
				console.log('User is logged in. Redirect to the parent-hub page')
	 		}
	 	} catch(e) {}
        } else {
	 	// todo: redirect to sign-up page
	 	console.log('User is not logged in. Redirect to login page')
	}
});

```

---

<div class="post-metadata">

**Author:** ![thomasj](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/thomasj/32/30791_2.png) [@thomasj](https://forum.wixstudio.com/u/thomasj)\
**Post date:** [October 25, 2023, 6:01pm UTC](https://forum.wixstudio.com/t/localstorage-getitem-returns-null/53284/2 "2023-10-25T18:01:40Z")

</div>

> I’ve manually set the `user` variable inside the local storage

Does this mean on you have set this value locally on your web browser?

In order to save values in local storage that are accessible via Velo, you should use the Wix Storage API’s [setItem()](https://www.wix.com/velo/reference/wix-storage-frontend/storage/setitem) method.

I recommend checking the Velo Example below to see it in use:

> **[Hello Storage](https://www.wix.com/velo/example/hello-storage)**
>
> Get started with browser storage.

---

<div class="post-metadata">

**Author:** ![user682](https://avatars.discourse-cdn.com/v4/letter/u/ad7895/32.png) [@user682](https://forum.wixstudio.com/u/user682)\
**Post date:** [October 26, 2023, 7:17am UTC](https://forum.wixstudio.com/t/localstorage-getitem-returns-null/53284/3 "2023-10-26T07:17:52Z")

</div>

Yes it is. So does this mean I can only access localStorage items stored using the Wix Storage API?

---

<div class="post-metadata">

**Author:** ![thomasj](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/thomasj/32/30791_2.png) [@thomasj](https://forum.wixstudio.com/u/thomasj)\
**Post date:** [October 26, 2023, 8:21pm UTC](https://forum.wixstudio.com/t/localstorage-getitem-returns-null/53284/4 "2023-10-26T20:21:32Z")

</div>

Yes, if you are attempting to retrieve localStorage items using the Wix Storage API, they must be defined using the [setItem()](https://www.wix.com/velo/reference/wix-storage-frontend/storage/setitem) method.
