User Plugin ignoring public path

I am using the User plugin and have added a path to a page I want to be public, using this example. But it just ignores it. I have tried different strings in the url of the page but it doesnt seem to work…

app.use(plugins.User, {
    model: session,
    public: path => path.indexOf("top/data") > -1
});

Here is my session model…

import { getUrl } from "../environments"

const url =  getUrl("sts") +  "/api/users";


webix.attachEvent("onBeforeAjax", 
	function(mode, url, data, request, headers, files, promise){
		headers["Authorization"] = "Bearer " + webix.storage.local.get("my_bearer");
	}
);

webix.attachEvent("onAjaxError", function(xhr){
	
	if (xhr.status == 401 ){
		logout();
		window.location.href = "/#!/login";
	}
	
 });

function status(){


	var bearer = webix.storage.local.get("my_bearer");

	if( bearer === undefined || bearer === null){
		return webix.promise.reject(null).fail(function(error){
			resolve(null);
		 });
	}

	var user = webix.storage.local.get("my_user");

	if( user === undefined || user === null){
		return webix.promise.reject(null).fail(function(error){
			resolve(null);
		 });
	}else{
		return webix.promise.resolve( user );
	}

	
	
}

function current(){

	return webix.ajax().get(url + "/current")
		.then(a => {
			a.json();
			webix.storage.local.put("my_user", a.json());
		});

}

function login(user, pass){

	
	return webix
	.ajax()
	.headers({"Content-type":"application/json"})
	.post( url + "/login", { "email": user, "password" : pass }
	)
	.then(a => {

		webix.storage.local.put("my_bearer", a.json().tokenString );
		current();
		return a.json()
	});

}

function logout(){
	return new webix.promise((resolve, reject) => {
		webix.storage.local.remove("my_bearer");
		webix.storage.local.remove("my_user");
		resolve(null)
	});
}

export default {
	status, login, logout
}

Hello @Splay,

I have tried different strings in the url of the page but it doesnt seem to work…

I’ve conducted a few tests locally, and I must say that the plugin worked flawlessly for me. Given your example, please ensure that you are providing the correct path, (i.e. "top/data" should be "/top/data" instead):

app.use(plugins.User, {
    model: session,
    public: path => path.indexOf("/top/data") > -1
});

Does the public() function not get triggered in your case at all? Could you please test it out and tell me if the method gets called?

Hi @Dzmitry thanks for your help,

It doesn’t get called at all I’m afraid.

I tried this code to test, neither debugger nor console get’s called…

this.use(plugins.User, { 
			model: session,
			user: { /* ... */ },
			ping: 15000, 
			public: function(path){
				debugger
				console.log("public called")
				return false; 
			}
		});