giving the user's email to the crisp session automatically

This commit is contained in:
Carter 2025-12-22 11:54:03 -06:00
parent e438e6fa96
commit 6737db1149
3 changed files with 28 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import { makeStyles } from '@mui/styles'
import { CssBaseline, Theme } from '@mui/material'
import { AppThemeProvider } from 'theme/AppThemeProvider'
import HTTPProvider from 'providers/http'
import { Crisp } from "crisp-sdk-web";
// import FirmwareLoader from './FirmwareLoader'
const reducer = (state: GlobalState, action: GlobalStateAction): GlobalState => {
@ -67,6 +68,9 @@ export default function UserWrapper(props: Props) {
const user_id = or(useAuth.user?.sub, "")
window.CRISP_RUNTIME_CONFIG = { session_merge: true };
Crisp.configure(import.meta.env.VITE_CRISP_WEBSITE_ID);
const loadUser = useCallback(() => {
if (!userAPI.getUserWithTeam) return;
if (hasFetched.current) return;
@ -100,6 +104,18 @@ export default function UserWrapper(props: Props) {
.finally(() => {
setLoading(false)
hasFetched.current = true;
if (global?.user && global?.user.settings.email) { // Assuming you have user object from your auth/settings
Crisp.user.setEmail(global?.user.settings.email);
// Optional: Set nickname or other info
Crisp.user.setNickname(global?.user.settings.name || "User");
Crisp.user.setPhone(global?.user.settings.phoneNumber);
// For extra security (marks email as verified, prevents spoofing):
// Crisp.user.setEmail(user.email, "your-hmac-signature-here"); // See Crisp docs for signing
// Optional: For session continuity across devices/browsers
Crisp.setTokenId(global?.user.id()); // e.g., your DB user ID
}
})
}, [setGlobal])