Please anyone ccan help me?
How can i avoid one member to be logged at 2 ou more PCs at same time??
Many thanks
Paulo
Please anyone ccan help me?
How can i avoid one member to be logged at 2 ou more PCs at same time??
Many thanks
Paulo
Hi,
can you please share your full use case? seems quite unique what about different tabs on the same computer? different browsers?
Shlomi
Shiomi, thanks for reply
If i use 2 diferent computers with diferent ips (exemple my home pc and my office pc), i wont avoid have acess to my members ares at same time.
If i already loggedin in one pc and try to enter by another i need logged out both or avoid that second one logged in.
MAny thanks
Paulo
My code is
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#loginButton”).label = “Logout”;
$w(“#MembersButton”).show();
}
else {
$w(“#loginButton”).label = “Login”;
$w(“#MembersButton”).hide();
}
} );
export function loginButton_onclick() {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginButton”).label = “Login”;
$w(“#MembersButton”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;
// prompt the user to log in
wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Members”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Members”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#loginButton”).label = “Logout”;
$w(“#MembersButton”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}
export function MembersButton_onclick() {
wixLocation.to(/Members/Update/${wixUsers.currentUser.id}
);
}
You can try to look into dynamic routers wix-router - Velo API Reference - Wix.com and manage a collection of your logged in users by yourself
good luck!
shlomi