Strange Database access permission error

Hi Wix team,
I have a strange issue (as always) with accessing my page with a table connected to a database. It happens only one time and randomly when i access my website just after turning on my computer . The error is like the attached image. I have full access to the database and I am logged in mode. After this error happens I can reload the page and everything will work as expected. I can then log off, log in and this error wont happen till i restart my pc and I access the website again(but this is random and I have only noticed this error when I use the website after a shutdown or restart of my computer). What might be the issue? anything with setting cookies ? I am using a chrome browser in pc .Please help. Thanks

Hi,
It seems like an issue with the collection permissions . Click here to learn more about How to Set Permissions for a Database Collection.

Best,
Tal.

Hi,
Thanks fr your reply. But as i said, the collection permissions are set correctly and this error only happens one time after pc restart. I can just reload the page when this error happens and everything will work as expected. So if the collection permission is set incorrectly,it should not also work the second time . So I think the problem is somewhere else… :frowning:


This is my collection permission settings

Hi,
I’ve forwarded the issue to the relevant department. I’ll get back to you once it’s resolved.

Have a good day,
Tal.

Hi Tal,

One more info regarding this issue. This error only happens if I directly go the website containing the table and database and login after the PC is started/restarted. (Example case : If I bookmarked the web page and directly visit the page without going to the homepage). This error is not happening for example if I first go to the home page or any other page without the table and database, then login and then visit the page containing the table and database.

After this error , I can reload the page and everything will work as usual(Both with direct web page visit or visiting the webs page after visiting any other web page or home page).

Just let me know if you have a solution for this bug. :slight_smile:

If you go to the page without logging in first, then you’ll get a permission error since the “Who can read from this collection” permission is set to “Site Member”. However, before the user has logged in, they are not yet a “site member” - they are merely an “anyone”. Change this setting to “Anyone” and it should work OK.

Hello Yisrael,

Thanks for your reply. But I guess u dint understood my problem yet. I will explain with a example:

I have a member only page with table and a data set connected to it with permissions like the attached image in my previous post. Now a member of my page bookmark this web page and try to access it after he starts the pc for the first time without going to my home page.
Now the website will detect that he don’t have access to the member only page and ask him to login as shown in the picture below.

Now he logins with his credentials and now the error happens and the table is stuck as shown in this image.

Now he can just reload the page or navigate to another page and come back to the page with table/dataset and then everything will work like this without any additional errors.

I dont know how wix backend code works and how you are detecting a loggedin user. But according to my basic understanding this is happening:

  1. website member tries to access a member only page directly containing a table and dataset.
  2. logging screen appears
  3. The user enters the credentials and is redirected to the webpage containing the table and dataset. But now I think the session storage for detecting a loggedin user is not set or detected by wix backend. So the error happens because of the dateset permision set as in my attached image in my previous post.

4. Now the user reloads the page or navigates to another page and come back to the old page. Now the wix backend detects the session storage and detects the loggedin user and everything works fine.

So according to my understanding the error happens when the wix backend is not detecting that the user is already loggged in and when it redirects the user to a page with the dataset with permissions as in the attached image in my previous post.

I tried your solution and it works but I guess your solution is not that perfect as then anyone can access the contents of the dataset and is not safe ( correct me if I am wrong ). Actually the problem will be solved when the wix system stores the info about the loggedin user before the dataset is loaded or accessed and I guess its the correct way of solving this issue(correct me if I am wrong ).

I hope you understood the issue. If u need I can also make a video and link it here. Hope I will get a solution/reply soon. Thanks.

Hi Yisrael,
After writing the above post I noticed one more issue. You can see a My posts button on my attached images above. I am using this button to show only the posts by the current user. Its hidden during the page load and I make it visible by detecting a loggedin user with some contnet in the database using the below code.

const linkField = "_id";
const currentUserId = wixUsers.currentUser.id;
$w.onReady(function () {
	session.removeItem("createMode");
	session.removeItem("createType");
	session.removeItem("itemObjid");

	if (wixWindow.rendering.renderCycle === 1) {
		$w("#sellandbuydataset").onReady(() => {
			wixData.query("Sell_And_Buy")
				.eq("_owner", currentUserId)
				.find()
				.then((results) => {
					if (results.items[0] !== undefined) {
						$w("#myPostsButton").show();
					} else {
						$w("#myPostsButton").hide();
					}
				});

			let numberOfItems = $w("#sellandbuydataset").getTotalCount();
			$w("#sellandbuydataset").getItems(0, numberOfItems)
				.then((result) => {
					let dynamicPageURLs = result.items.map(item => item[linkField]);
					local.setItem('dynamicPageURLs', dynamicPageURLs);
				});
		});
	}
});

And now this My posts button will not be shown when the user directly visit the website after login as the wix backend is not detecting that the user has logged in and it will be only be visible after the user reloads the page again or go to another page and come back to this page.

So the issue wont be solved just by changing the dataset permissions.Basically a lot of functionality with user detection and permissions will be broken and wont work in wix if a user access a page directly for example with a bookmark. It need to be implemented in the wix backend to detect the current user before the page starts to load.

Waiting for your reply. Thanks

You need to handle the case of a user logging in after arriving at the page. You can use the wix-users.onLogin() event handler function to handle the logged in event. Use the currentUser.loggedIn property to make sure the user has been logged in.

Here’s a “template” of what the page code should look like:

import wixUsers from 'wix-users';

$w.onReady( () => {
    setupPage();
    wixUsers.onLogin( (user) => {
        setupPage();
    } );  
} );

export function setupPage() {
    if(wixUsers.currentUser.loggedIn) {
        // do page stuff for a logged in user
    }
    else {
        // do page stuff for a visitor
    }
}

I hope this helps.

Yisrael

Hi Yisrael,

Thanks a lot for your reply. Logically ur code should work in my case. But for me the onlogin event is not running even after logging. My code is like this:

const linkField = "_id";
var currentUserId = wixUsers.currentUser.id;  //////@YISRAEL THIS WAS AN ERROR I 
//CORRECTED FROM  PREVIOUS CODE. IT SHOULD BE VAR INSTEAD OF CONST
///////////////////////////////////////////////////////////////////////////Variables/////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////On Ready//////////////////////////////////////////////////////////////////////
$w.onReady(() => {
	setupPage();
	wixUsers.onLogin( (user) => {
		setupPage();
		console.log("login successful");
	});
	session.removeItem("createMode");
	session.removeItem("createType");
	session.removeItem("itemObjid");

});


///////////////////////////////////////////////////////////////////////////On Ready///////////////////////////////////////////////////////////////////////
export function setupPage() {
	if (wixUsers.currentUser.loggedIn) {
		$w("#sellandbuydataset").onReady(() => {

			currentUserId = wixUsers.currentUser.id;
			console.log(currentUserId);

			wixData.query("Sell_And_Buy")
				.eq("_owner", currentUserId)
				.find()
				.then((results) => {

					console.log("text22")
					if (results.items[0] !== undefined) {
						$w("#myPostsButton").show();

					} else {
						$w("#myPostsButton").hide();

					}

				});

			let numberOfItems = $w("#sellandbuydataset").getTotalCount();
			$w("#sellandbuydataset").getItems(0, numberOfItems)
				.then((result) => {
					let dynamicPageURLs = result.items.map(item => item[linkField]);
					local.setItem('dynamicPageURLs', dynamicPageURLs);
				});
		});

	} else {

	}
}

When I use this code, the login successful is not being printed on my console window even after i tried logging in Admin account and a member account. But strangely the flow is going inside the if condition:(wixUsers.currentUser.loggedIn).

Currently I have set the dataset read permission to anyone and using the above code everything will work fine.

But I need it to set it to site member and then the previous errors (see my previous posts ) will appear as the wixusers.onLogin() is not being run.

Do you see any mistake in my code.?