UNPKG

casdoor-react-sdk

Version:
61 lines (60 loc) 2.44 kB
"use strict"; // Copyright 2022 The Casdoor Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.isSilentSigninRequired = exports.SilentSignin = void 0; const React = require("react"); class SilentSignin extends React.Component { constructor() { super(...arguments); this.listenForSilentSigninEvents = () => { const { handleReceivedSilentSigninSuccessEvent, handleReceivedSilentSigninFailureEvent, } = this.props; window.addEventListener("message", (event) => { const message = event.data; if (message.tag !== "Casdoor" || message.type !== "SilentSignin") { return; } if (message.data === "success") { if (handleReceivedSilentSigninSuccessEvent) { handleReceivedSilentSigninSuccessEvent(message); } } else { if (handleReceivedSilentSigninFailureEvent) { handleReceivedSilentSigninFailureEvent(message); } } }); }; } componentDidMount() { this.listenForSilentSigninEvents(); } render() { const { isLoggedIn, sdk } = this.props; if (window !== window.parent) { return null; } if (isLoggedIn()) { return null; } return (React.createElement("iframe", { id: "iframeTask", src: `${sdk.getSigninUrl()}&silentSignin=1`, style: { display: "none" }, frameBorder: "no" })); } } exports.SilentSignin = SilentSignin; function isSilentSigninRequired() { const params = new URLSearchParams(window.location.search); return params.get("silentSignin") === "1"; } exports.isSilentSigninRequired = isSilentSigninRequired;