Commit d02ee469 by Arjun Jhukal

updated the seon provider changes

parent 0fde51fe
"use client"; "use client";
import React, { createContext, useContext, useEffect, useState } from "react"; import React, { createContext, useContext, useEffect, useState } from "react";
import seon from "@seontechnologies/seon-javascript-sdk";
type SeonContextType = { type SeonContextType = {
deviceId?: string; deviceId?: string;
loading: boolean; loading: boolean;
sessionData?: any; // For storing additional session information if available sessionData?: any;
}; };
const SeonContext = createContext<SeonContextType>({ const SeonContext = createContext<SeonContextType>({
deviceId: undefined, deviceId: undefined,
loading: true, loading: true,
sessionData: undefined sessionData: undefined,
}); });
export const useSeon = () => useContext(SeonContext); export const useSeon = () => useContext(SeonContext);
...@@ -21,33 +20,41 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children ...@@ -21,33 +20,41 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
useEffect(() => { useEffect(() => {
// Initialize the SDK on page load let seon: any;
seon.init({
behavioralDataCollection: { const initSeon = async () => {
targets: 'input[type="text"], .behavior', if (typeof window === "undefined") return; // safeguard
formFilloutDurationTargetId: "myForm",
}, try {
}); // Dynamically import so it only runs in browser
const seonModule = await import("@seontechnologies/seon-javascript-sdk");
// Collect fingerprint session seon = seonModule.default || seonModule;
seon.getSession()
.then((session: string) => { seon.init({
// session holds the encrypted fingerprint as a base64 encoded string behavioralDataCollection: {
// This is what you send to your backend for fraud detection targets: 'input[type="text"], .behavior',
formFilloutDurationTargetId: "myForm",
},
});
const session = await seon.getSession();
console.log("Device fingerprint session:", session); console.log("Device fingerprint session:", session);
setDeviceId(session); setDeviceId(session);
setLoading(false); } catch (err) {
})
.catch((err: any) => {
console.error("SEON init error:", err); console.error("SEON init error:", err);
} finally {
setLoading(false); setLoading(false);
}); }
};
initSeon();
// Cleanup: disable behavioral tracking when component unmounts
return () => { return () => {
seon.init({ if (seon) {
behavioralDataCollection: { targets: "" }, // disables tracking try {
}); seon.init({ behavioralDataCollection: { targets: "" } });
} catch { }
}
}; };
}, []); }, []);
...@@ -56,4 +63,4 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children ...@@ -56,4 +63,4 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children
{children} {children}
</SeonContext.Provider> </SeonContext.Provider>
); );
}; };
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment