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 | 'use client';
import { track } from '@lib/track';
import { getLocalStorage } from '@lib/utils/localStorage';
import React from 'react';
import { decodeJwt } from 'jose';
interface TrackProviderProps {
children: React.ReactNode;
}
export function TrackProvider({ children }: TrackProviderProps) {
React.useEffect(() => {
const accessToken = getLocalStorage('accessToken');
if (!accessToken) {
track.initialize({});
} else {
const { sub } = decodeJwt(accessToken);
(async () => {
track.initialize({
userId: sub
});
})();
}
}, []);
// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{children}</>;
}
|