NovuN
Novuβ€’2y ago
David 😎

Novu Headless - notifications not showing for custom subscriber IDs

I have an app that accepts user's first name, last name, and first name. Then, it generates an ID similar 7sa7ejga which is also used to create the user's Subscriber ID immediately after signing in.

Now, I'm trying to fetch the user's notifications via Novu Headless but it's empty but it's showing on my Novu Activity Dashboard.

Here is the code snippet for fetching the notifications:
    const fetchNotifications = useCallback(() => {
        const headlessService = headlessServiceRef.current;
        if (!headlessService) return;
        headlessService.fetchNotifications({
            listener: ({ data, error, isError, isFetching, isLoading, status }) => {
             console.log({ data, error, isError, isFetching, isLoading, status });
            },
            onSuccess: (response: IPaginatedResponse<IMessage>) => {
                console.log({
                    notifications: response,
                });
                setNotifications(response.data);
            },
            page: 1, // page number to be fetched
        });
    }, []);


    useEffect(() => {
        const headlessService = new HeadlessService({
            applicationIdentifier: process.env.NEXT_PUBLIC_NOVU_APP_ID!,
            subscriberId: localStorage.getItem("subscriberId")!,
        });
        headlessService.initializeSession({
            listener: (res: FetchResult<ISession>) => {
                headlessServiceRef.current = headlessService;
                console.log(res);
            },
            onSuccess: (session: ISession) => {
                fetchNotifications();
            },
            onError: (error) => {
                console.error(error);
            },
        });
    }, [fetchNotifications]);
Screenshot_2024-06-19_at_12.28.52.png
Screenshot_2024-06-19_at_12.32.31.png
Was this page helpful?