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,7 +20,16 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children ...@@ -21,7 +20,16 @@ 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;
const initSeon = async () => {
if (typeof window === "undefined") return; // safeguard
try {
// Dynamically import so it only runs in browser
const seonModule = await import("@seontechnologies/seon-javascript-sdk");
seon = seonModule.default || seonModule;
seon.init({ seon.init({
behavioralDataCollection: { behavioralDataCollection: {
targets: 'input[type="text"], .behavior', targets: 'input[type="text"], .behavior',
...@@ -29,25 +37,24 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children ...@@ -29,25 +37,24 @@ export const SeonProvider: React.FC<{ children: React.ReactNode }> = ({ children
}, },
}); });
// Collect fingerprint session const session = await seon.getSession();
seon.getSession()
.then((session: string) => {
// session holds the encrypted fingerprint as a base64 encoded string
// This is what you send to your backend for fraud detection
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 { }
}
}; };
}, []); }, []);
......
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