# Failed to load initial data 

**URL:** <https://forum.wixstudio.com/t/failed-to-load-initial-data/17819>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [June 25, 2019, 9:22am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819 "2019-06-25T09:22:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kana](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kana/32/10533_2.png) [@kana](https://forum.wixstudio.com/u/kana)\
**Post date:** [June 25, 2019, 9:22am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819/1 "2019-06-25T09:22:25Z")

</div>

Dear All,  
I have a lightbox for users to log-in. The moment when it pop up, "Failed to load initial data " showed in console log. What is it? User can log-in without problem even there is error.

This is my code:

import wixUsers **from** ‘wix-users’;  
import wixWindow **from** ‘wix-window’;  
import wixLocation **from** ‘wix-location’;  
import wixData **from** ‘wix-data’;

$w.onReady(() =\> {

**let** user = wixUsers.currentUser;  
**let** isLoggedIn = user.loggedIn;

```
$w("#forgetpw").onClick((event) => { 
    wixUsers.promptForgotPassword() 
       . **catch** ((err) => { 

```

**let** errorMsg = err;  
});  
});

**if** (isLoggedIn === “true”) {  
wixWindow.lightbox.close();  
wixWindow.openLightbox(“confirm\_apply”);  
} **else** {  
// open light box  
$w(“#loginenter”).onClick((event) =\> {

**let** email = $w(“#loginmail”).value;  
**let** password = $w(“#loginpw”).value;

```
        wixUsers.login(email, password) 
            .then(() => { 
                console.log("User is logged in"); 
                wixWindow.lightbox.close(); 
                wixLocation.to(wixLocation.url); 
            }) 
            . **catch** ((err) => { 
                console.log(err); 
                $w("#loginerror").expand(); 
            }); 
    }); 

    $w("#closebutton").onClick((event) => { 
        wixWindow.lightbox.close(); 
       
    }); 
} 

```

});

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 25, 2019, 10:35am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819/2 "2019-06-25T10:35:24Z")

</div>

```javascript
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function () {
 $w("#forgotPassword").onClick( (event) => {
    //wixWindow.lightbox.close()
   wixUsers.promptForgotPassword()
   .then( ( ) => {
   //
   } )
    .catch( (err) => {
    let errorMsg = err; //"The user closed the forgot password dialog"
    });
 });
});

export function loginButton_onclick(event) {

 let email = $w("#email").value;
 let password = $w("#password").value;

 wixUsers.login(email, password)
   .then( () => {
     console.log("User is logged in");
     wixWindow.lightbox.close();
     wixLocation.to(wixLocation.url); //This reloads the same page.
   } )
    .catch( (err) => {
     console.log(err);
     $w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
   } ); 
}

```

---

<div class="post-metadata">

**Author:** ![kana](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kana/32/10533_2.png) [@kana](https://forum.wixstudio.com/u/kana)\
**Post date:** [June 26, 2019, 2:22am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819/3 "2019-06-26T02:22:13Z")

</div>

Thank you, I have just found that it is not because of the code in the light box as I have copied the above code but I still got the same error. I have even delete all the code but still the same.

It is actually because of my “Site” code. I have a function which check the dataset to see if the member logged in has finished their profile page (if no record found in dataset, that’s mean need to show the create button). If I change the dataset to “everyone can read”, the error disappear but is it safe to do so in the view of protecting my members’ information?

This is my code:

**function** checklogin() {

**if** (wixUsers.currentUser.loggedIn) {  
**let** user = wixUsers.currentUser;  
**let** userId = user.id;  
$w(“#login”).label = “Logout”;

```
    user.getEmail() 
        .then((email) => { 

```

**let** userEmail = email;  
console.log(userEmail);  
wixData.query(“cand\_reg”)  
.eq(“cand\_mail”, email)  
.find()  
.then((results) =\> {  
**if** (results.items.length === 0) {

```
                        $w("#createaccount").show(); 
                        $w("#myaccount").hide(); 

                    } **else** { 

```

**let** item = results.items[0];  
[//console.log](https://console.log)(item);  
[//console.log](https://console.log)(user.id);  
$w(“#myaccount”).show();  
$w(“#createaccount”).hide();  
}

```
                }) 
        }) 

} **else** { 
    $w("#login").label = "Login"; 
    $w("#myaccount").hide(); 
    $w("#createaccount").hide(); 
} 

```

}

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 26, 2019, 10:45am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819/4 "2019-06-26T10:45:02Z")

</div>

Why not just do a Members Profile as in this tutorial?  
[https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area](https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area)  
[https://www.youtube.com/watch?v=Orl8GJNzG5s](https://www.youtube.com/watch?v=Orl8GJNzG5s) - Nayeli (Code Queen) video tutorial for above.

Updated video from Nayeli.  
[https://www.youtube.com/watch?v=yLCOqsVHhD0](https://www.youtube.com/watch?v=yLCOqsVHhD0)

---

<div class="post-metadata">

**Author:** ![kana](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kana/32/10533_2.png) [@kana](https://forum.wixstudio.com/u/kana)\
**Post date:** [June 27, 2019, 3:00am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819/5 "2019-06-27T03:00:21Z")

</div>

Thank you 🙂  
Actually I have already read all of them. What I want to do is a bit different but seems that I am not at that level yet…So I have just copy and do the same, still the error appear.

---

<div class="post-metadata">

**Author:** ![kana](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kana/32/10533_2.png) [@kana](https://forum.wixstudio.com/u/kana)\
**Post date:** [June 27, 2019, 9:08am UTC](https://forum.wixstudio.com/t/failed-to-load-initial-data/17819/6 "2019-06-27T09:08:33Z")

</div>

I just found the problem, I have drop a dataset (which I don’t need) to the log-in lightbox by mistake!!!  
So silly…
