Storage.readSync() function returns null in other script

I have made a UserContext.js which handles getting and setting the current logged in user for the app. It has two function; one takes a JSON object and writes it with Storage.writeSync() and the other gets the previously stored user with Storage.readSync() and returns it.


var Observable = require('FuseJS/Observable');
var Storage = require("FuseJS/Storage");

function getUser() { 

return new Promise(function(resolve, reject) {

	var contents = Storage.readSync("User.json");
	var user = JSON.parse(contents);

function setUser(userObject) { 
return new Promise(function(resolve, reject) {

	var success = Storage.writeSync("User.json", JSON.stringify(userObject));
	if(success) {
		console.log("Successfully wrote to file");
	else {
		console.log("An error occured!");


module.exports = {
getUser: getUser,
setUser: setUser

Now I have tested getting the JSON data with readSync() inside UserContext.js and print it and it works just fine.
However when I try to do

var User = UserContext.getUser();

in LoginPage.js then it just returns null…
Anyone know why this happens and have a solution? The variable should be available throughout the app once it’s fetched and written.

Uhm. getUser returns a promise in your code, so the correct usage of the function would be:

 UserContext.getUser().then(function(User) {

Oh sorry…
It takes some time getting used to this after doing tons of C# all the way (Y)
Thank you!