Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 'use client'; import { track } from '@lib/track'; import { getLocalStorage } from '@lib/utils/localStorage'; import React from 'react'; import { decodeJwt } from 'jose'; import { getMe } from '@lib/apis/core/getMe'; import { useSearchParams } from 'next/navigation'; import { coreDirectDevelopmentApi, coreDirectApi as coreDirectProductionApi } from '@lib/apis/core'; interface TrackProviderProps { children: React.ReactNode; } export default function TrackProvider({ children }: TrackProviderProps) { const searchParams = useSearchParams(); React.useEffect(() => { const isDevelopment = searchParams.get('tset') === 'htua'; const coreDirectApi = isDevelopment ? coreDirectDevelopmentApi : coreDirectProductionApi; const accessToken = getLocalStorage('accessToken'); if (!accessToken) { track.initialize({}); } else { const { sub } = decodeJwt(accessToken); (async () => { const data = await coreDirectApi.getMe(accessToken); track.initialize({ userId: sub, loginPlatform: data?.credentials[0].provider }); })(); } }, []); // eslint-disable-next-line react/jsx-no-useless-fragment return <>{children}</>; } |