daphnis/app/(sharing)/[token]/[id]/page.tsx

50 lines
997 B
TypeScript
Raw Normal View History

2024-06-29 18:43:11 +00:00
import { getAuth } from "@/auth/queries/getauth";
2024-06-29 07:02:21 +00:00
import { generatePlaylogId, getSongsWithTitles } from "@/lib/api";
2024-06-29 05:22:22 +00:00
import { shareScore } from "../token";
export default async function Share({
params,
}: {
params: { token: string; id: string };
}) {
const { token, id } = params;
// Verify the token
const tokenResult = await shareScore(token);
if (tokenResult.error) {
2024-06-29 07:02:21 +00:00
2024-06-29 05:22:22 +00:00
return <p>{tokenResult.error}</p>;
}
2024-06-29 18:43:11 +00:00
const { user } = await getAuth();
if (!user?.UserId) {
return {
error:"no user id"
}
}
const userId = user?.UserId;
2024-06-29 05:22:22 +00:00
const playlogId = parseInt(id);
const songsData = await getSongsWithTitles(userId);
2024-06-29 07:02:21 +00:00
const playlogIds = await generatePlaylogId(playlogId);
2024-06-29 05:22:22 +00:00
2024-06-29 07:02:21 +00:00
const matchSongToPlaylogId = songsData.filter((song) =>
2024-06-29 05:22:22 +00:00
playlogIds.includes(song.id)
);
2024-06-29 07:02:21 +00:00
const songTitles = matchSongToPlaylogId.map((song) => song.title);
2024-06-29 05:22:22 +00:00
return (
<ul>
{songTitles.map((title) => (
<li key={title}>{title}</li>
))}
</ul>
);
}