Skip to content

Instantly share code, notes, and snippets.

const receiveMessage = event => {
// Do we trust the sender of this message? (might be
// different from what we originally opened, for example).
if (event.origin !== BASE_URL) {
return;
}
const { data } = event;
// if we trust the sender and the source is our popup
if (data.source === 'lma-login-redirect') {
// get the URL params and redirect to our server to use Passport to auth/login
export default () => {
useEffect(() => {
// get the URL parameters which will include the auth token
const params = window.location.search;
if (window.opener) {
// send them to the opening window
window.opener.postMessage(params);
// close the popup
window.close();
}
let windowObjectReference = null;
let previousUrl = null;
const openSignInWindow = (url, name) => {
// remove any existing event listeners
window.removeEventListener('message', receiveMessage);
// window features
const strWindowFeatures =
'toolbar=no, menubar=no, width=600, height=700, top=100, left=100';