File size: 1,318 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
function supportUserFn( { user, token, path, authorized } ) {
const url = window.location.toString();
if ( url.indexOf( '?' ) > 0 ) {
const cleanUrl = url.substring( 0, url.indexOf( '?' ) );
window.history.replaceState( {}, document.title, cleanUrl );
}
if ( authorized ) {
window.sessionStorage.setItem( 'boot_support_user', window.JSON.stringify( { user, token } ) );
}
// Only redirect to same-domain
const redirectUrl = new URL( url );
redirectUrl.pathname = path ? decodeURIComponent( path ) : '/';
redirectUrl.search = '';
window.location.replace( redirectUrl.href );
}
function SupportUser( { supportUser, supportToken, supportPath, authorized = false } ) {
return (
<html lang="en">
<body>
{ /* eslint-disable react/no-danger */ }
<script
dangerouslySetInnerHTML={ {
__html: `
const supportUserFn = ${ supportUserFn.toString() };
supportUserFn( {
user: ${ supportUser && `"${ encodeURIComponent( supportUser ) }"` },
token: ${ supportToken && `"${ encodeURIComponent( supportToken ) }"` },
path: ${ supportPath && `"${ encodeURIComponent( supportPath ) }"` },
authorized: ${ authorized }
} );
`,
} }
/>
);
}
export default SupportUser;
|