2021-10-16 03:07:13 +08:00
|
|
|
import { PadsSessions } from '/imports/api/pads';
|
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
const COOKIE_CONFIG = window.meetingClientSettings.public.pads.cookie;
|
2021-10-16 03:07:13 +08:00
|
|
|
const PATH = COOKIE_CONFIG.path;
|
|
|
|
const SAME_SITE = COOKIE_CONFIG.sameSite;
|
|
|
|
const SECURE = COOKIE_CONFIG.secure;
|
|
|
|
|
|
|
|
const getSessions = () => {
|
|
|
|
const padsSessions = PadsSessions.findOne({});
|
|
|
|
|
|
|
|
if (padsSessions) {
|
|
|
|
return padsSessions.sessions;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
|
|
|
const hasSession = (externalId) => {
|
|
|
|
const padsSessions = PadsSessions.findOne({});
|
|
|
|
|
|
|
|
if (padsSessions && padsSessions.sessions) {
|
|
|
|
return padsSessions.sessions.some(session => session[externalId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setCookie = (sessions) => {
|
|
|
|
const sessionIds = sessions.map(session => Object.values(session)).join(',');
|
|
|
|
document.cookie = `sessionID=${sessionIds}; path=${PATH}; SameSite=${SAME_SITE}; ${SECURE ? 'Secure' : ''}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getSessions,
|
|
|
|
hasSession,
|
|
|
|
setCookie,
|
|
|
|
};
|