mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-20 04:21:23 +00:00
* feat: process request record from sentry locally * feat: added analytics for logged in users
33 lines
908 B
TypeScript
33 lines
908 B
TypeScript
import type { FC, PropsWithChildren } from 'react'
|
|
import { useEffect } from 'react'
|
|
import { identify, resetIdentity } from '@/lib/analytics/identify'
|
|
import { useSession } from './auth-client'
|
|
import { useSessionInfo } from './sessionStorage'
|
|
|
|
export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
const { data, isPending } = useSession()
|
|
const { updateSessionInfo } = useSessionInfo()
|
|
|
|
// biome-ignore lint/correctness/useExhaustiveDependencies: only re-run when data changes
|
|
useEffect(() => {
|
|
if (!isPending) {
|
|
updateSessionInfo({
|
|
session: data?.session,
|
|
user: data?.user,
|
|
})
|
|
|
|
if (data?.user?.id) {
|
|
identify({
|
|
id: data.user.id,
|
|
email: data.user.email,
|
|
name: data.user.name || undefined,
|
|
})
|
|
} else {
|
|
resetIdentity()
|
|
}
|
|
}
|
|
}, [data, isPending])
|
|
|
|
return <>{children}</>
|
|
}
|