feature/IO-3255-simplified-parts-management -Checkpoint
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { LockOutlined, UserOutlined } from "@ant-design/icons";
|
||||
import { Button, Form, Input, Typography } from "antd";
|
||||
import queryString from "query-string";
|
||||
import React, { useEffect } from "react";
|
||||
import { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { Link, useLocation, useNavigate } from "react-router-dom";
|
||||
@@ -42,6 +42,42 @@ export function SignInComponent({ emailSignInStart, currentUser, signInError, se
|
||||
}
|
||||
}, [currentUser, redirect, navigate]);
|
||||
|
||||
// Add event listener for seamless login
|
||||
useEffect(() => {
|
||||
const handleSeamlessLogin = (event) => {
|
||||
const { email, password, origin: requestOrigin } = event.detail || {};
|
||||
|
||||
// Validate input
|
||||
if (!email || !password) {
|
||||
window.parent.postMessage(
|
||||
{ type: "seamlessLoginResponse", status: "error", message: "Email and password are required" },
|
||||
requestOrigin || "*" // Use specific origin for security if known
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the user is already logged in
|
||||
if (currentUser.authorized === true) {
|
||||
console.log("User is already logged in, redirecting...");
|
||||
navigate(redirect || "/manage/");
|
||||
window.parent.postMessage({ type: "seamlessLoginResponse", status: "already_logged_in" }, requestOrigin || "*");
|
||||
return;
|
||||
}
|
||||
|
||||
// Proceed with sign-in if not logged in
|
||||
emailSignInStart(email, password);
|
||||
window.parent.postMessage({ type: "seamlessLoginResponse", status: "login_attempted" }, requestOrigin || "*");
|
||||
};
|
||||
|
||||
// Add event listener for custom seamless login event
|
||||
window.addEventListener("seamlessLoginRequest", handleSeamlessLogin);
|
||||
|
||||
// Cleanup to remove the event listener on unmount
|
||||
return () => {
|
||||
window.removeEventListener("seamlessLoginRequest", handleSeamlessLogin);
|
||||
};
|
||||
}, [emailSignInStart, currentUser, navigate, redirect]);
|
||||
|
||||
return (
|
||||
<div className="login-container">
|
||||
<div className="login-logo-container">
|
||||
|
||||
Reference in New Issue
Block a user