this is for a live class site, as they don’t want to provide MULTIPLE Login from a user
Yeah Try this …
This will show a box in a page when the user have logged in 2 devices, browser etc in real Time …
First you should create a new web module (.jsw) file and rename it as - realtime
Code for the web module file →
// Filename: backend/realtime.jsw (web modules need to have a .jsw extension)
import { publish } from 'wix-realtime-backend';
export function publishMessage(message) {
const channel2 = { name: 'messaging' };
const payload = {message};
return publish(channel2, payload);
}
Code for the login page →
import wixUsers from 'wix-users';
import { publishMessage } from 'backend/realtime';
$w.onReady(function () {
$w('#submitButtton').onClick((event) => { // login button
let email = $w('#email').value; //email input
let password = $w('#password').value; //password input
wixUsers.login(email, password)
wixUsers.onLogin((user) => {
let userId = user.id;
let message = userId;
return publishMessage(message);
});
});
});
Code for the page where the box should be shown or the user will be logged out->
#box1 - the box to show ()
import * as realtime from 'wix-realtime';
import wixUsers from 'wix-users';
$w.onReady(function () {
$w('#box1').hide();
const channel2 = { name: 'messaging' };
realtime.subscribe(channel2, type);
});
async function type({ payload }) {
if (payload.message === wixUsers.currentUser.id) {
wixUsers.logout();
//or
if ($w('#box1').hidden) {
$w('#box1').show('fade');
setTimeout(() => $w('#box1').hide('fade'), 10000);
} else {
setTimeout(() => type({ payload }), 10000);
}
}
}