Update src/hooks/courses/useCourseData.js

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Austin Kelsay 2025-05-12 09:44:29 -05:00 committed by GitHub
parent f8bd1ddb43
commit bac65c0dd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 its 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;