From bac65c0dd3f551c8bf658b4ff3683c4ec811af39 Mon Sep 17 00:00:00 2001 From: Austin Kelsay <53542748+AustinKelsay@users.noreply.github.com> Date: Mon, 12 May 2025 09:44:29 -0500 Subject: [PATCH] Update src/hooks/courses/useCourseData.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/hooks/courses/useCourseData.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/hooks/courses/useCourseData.js b/src/hooks/courses/useCourseData.js index c6a6663..def9f34 100644 --- a/src/hooks/courses/useCourseData.js +++ b/src/hooks/courses/useCourseData.js @@ -24,8 +24,22 @@ const useCourseData = (ndk, fetchAuthor, router) => { let id; const fetchCourseId = async () => { - if (slug.includes('naddr')) { - const { data } = nip19.decode(slug); + // Normalise slug to a string and exit early if it’s still falsy + const slugStr = Array.isArray(slug) ? slug[0] : slug; + if (!slugStr) { + showToast('error', 'Error', 'Invalid course identifier'); + return null; + } + + if (slugStr.includes('naddr')) { + let data; + try { + ({ data } = nip19.decode(slugStr)); + } catch (err) { + showToast('error', 'Error', 'Malformed naddr'); + return null; + } + if (!data?.identifier) { showToast('error', 'Error', 'Resource not found'); return null;