WIP Client login #20

Open
sosthene wants to merge 18 commits from client_login into dev
Showing only changes of commit 0536b98ea8 - Show all commits

View File

@ -21,6 +21,8 @@ import UserStore from "@Front/Stores/UserStore";
import AuthModal from "src/sdk/AuthModal"; import AuthModal from "src/sdk/AuthModal";
import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService";
import MessageBus from "src/sdk/MessageBus";
import { resolve } from "path";
export enum LoginStep { export enum LoginStep {
EMAIL, EMAIL,
@ -41,6 +43,7 @@ export default function Login() {
const [totpCode, setTotpCode] = useState<string>(""); const [totpCode, setTotpCode] = useState<string>("");
const [email, setEmail] = useState<string>(""); const [email, setEmail] = useState<string>("");
const [partialPhoneNumber, setPartialPhoneNumber] = useState<string>(""); const [partialPhoneNumber, setPartialPhoneNumber] = useState<string>("");
const [sessionId, setSessionId] = useState<string>("");
const [validationErrors, setValidationErrors] = useState<ValidationError[]>([]); const [validationErrors, setValidationErrors] = useState<ValidationError[]>([]);
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
@ -92,10 +95,13 @@ export default function Login() {
// If the code is valid setting it in state // If the code is valid setting it in state
if (res.validCode) { if (res.validCode) {
setTotpCode(values["totpCode"]); setTotpCode(values["totpCode"]);
setSessionId(res.sessionId); // Store the session ID
} }
*/ */
if ('1234' === values["totpCode"]) { if ('1234' === values["totpCode"]) {
setTotpCode(values["totpCode"]); setTotpCode(values["totpCode"]);
// For testing, set a mock session ID
setSessionId("mock-session-id-123");
} }
setValidationErrors([]); setValidationErrors([]);
@ -265,17 +271,43 @@ export default function Login() {
{isAuthModalOpen && <AuthModal {isAuthModalOpen && <AuthModal
isOpen={isAuthModalOpen} isOpen={isAuthModalOpen}
onClose={() => { onClose={() => {
CustomerService.getCustomers().then((processes: any[]) => { // After 4nk authentication is complete, get the process for the pairing ID
if (processes.length > 0) { MessageBus.getInstance().initMessageListener();
const customers: any[] = processes.map((process: any) => process.processData); MessageBus.getInstance().isReady().then(async () => {
const customer: any = customers.find((customer: any) => customer.contact.email === email); try {
if (customer) { // Find the customer
UserStore.instance.connect(customer); const customer: any = (await CustomerService.getCustomers())
.map((process: any) => process.processData)
.find((customer: any) => customer.contact.email === email);
// Get the pairing ID
const pairingId = await MessageBus.getInstance().getPairingId();
console.log('[Login] Got pairing ID:', pairingId);
// Get all processes
const processes = await MessageBus.getInstance().getProcesses();
console.log('[Login] Got processes:', Object.keys(processes));
const targetProcess = processes[pairingId];
if (targetProcess) {
console.log('[Login] Found target process:', targetProcess);
// Connect the user with the process data
UserStore.instance.connect(customer /*targetProcess*/);
router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path); router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path);
} else {
console.error('[Login] No process found for pairing ID:', pairingId);
// Handle the case where no process is found
} }
MessageBus.getInstance().destroyMessageListener();
} catch (error) {
console.error('[Login] Error getting process:', error);
MessageBus.getInstance().destroyMessageListener();
} }
setIsAuthModalOpen(false);
}); });
setIsAuthModalOpen(false);
}} }}
/>} />}
</div> </div>