forked from PolarisPyra/daphnis
fixed link sharing page not showing other users scores when logged in
This commit is contained in:
parent
7841fe8ff9
commit
90ae8fc48c
@ -1,6 +1,4 @@
|
||||
"use server";
|
||||
|
||||
import { getAuth } from "@/auth/queries/getauth";
|
||||
import { artemis, daphnis } from "@/lib/prisma";
|
||||
import type * as Prisma from "@prisma/client";
|
||||
|
||||
@ -11,14 +9,40 @@ type LinkSharingToken = {
|
||||
playlogId: number;
|
||||
};
|
||||
|
||||
export async function getSharedSong() {
|
||||
const { user } = await getAuth();
|
||||
|
||||
export async function getSharedSong(token: string) {
|
||||
try {
|
||||
const linkSharingToken = await daphnis.linkSharingToken.findFirst({
|
||||
where: {
|
||||
token: token,
|
||||
},
|
||||
select: {
|
||||
playlogId: true,
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
const user = await daphnis.user.findUnique({
|
||||
where: {
|
||||
id: linkSharingToken!.userId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
UserId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
if (!linkSharingToken) {
|
||||
throw new Error("Invalid or expired token");
|
||||
}
|
||||
|
||||
const songs: ChuniScorePlaylog[] =
|
||||
await artemis.chuni_score_playlog.findMany({
|
||||
where: {
|
||||
user: user?.UserId,
|
||||
user: user.UserId,
|
||||
},
|
||||
orderBy: {
|
||||
userPlayDate: "desc",
|
||||
|
@ -18,7 +18,6 @@ export default async function Share({
|
||||
}) {
|
||||
const { token, id } = params;
|
||||
|
||||
// Verify the token
|
||||
const tokenResult = await shareScore(token);
|
||||
|
||||
if (tokenResult.error) {
|
||||
@ -27,10 +26,13 @@ export default async function Share({
|
||||
|
||||
const playlogId = parseInt(id);
|
||||
|
||||
const songsData = await getSharedSong();
|
||||
const songsData = await getSharedSong(token);
|
||||
const playlogIds = await getPlaylogId(playlogId);
|
||||
|
||||
// Filter songsData to match the playlogIds
|
||||
if (!songsData) {
|
||||
return <p>Error: Something went wrong</p>;
|
||||
}
|
||||
|
||||
const chunithm: chunithm[] = songsData.filter((song) =>
|
||||
playlogIds.includes(song.id),
|
||||
);
|
||||
@ -42,7 +44,7 @@ export default async function Share({
|
||||
{chunithm.map((song) => (
|
||||
<div key={song.id} className="w-full">
|
||||
<span className="text-center text-xl font-bold text-primary text-white">
|
||||
Song: {song.title}
|
||||
{song.title}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@ -52,7 +54,7 @@ export default async function Share({
|
||||
{chunithm.map((song) => (
|
||||
<div key={song.id} className="w-full">
|
||||
<span className="text-xl font-bold text-primary text-white">
|
||||
Artist: {song.artist}
|
||||
{song.artist}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
|
@ -21,15 +21,16 @@ const ActionsCell: React.FC<ActionsCellProps> = ({ row }) => {
|
||||
const router = useRouter();
|
||||
|
||||
const handleGenerateShareToken = async () => {
|
||||
const { token, error } = await generateShareToken(row.original.id);
|
||||
if (error) {
|
||||
setError(error);
|
||||
} else {
|
||||
const newTab = window.open(`/${token}/${row.original.id}`);
|
||||
const response = await generateShareToken(row.original.id);
|
||||
if (response.error) {
|
||||
setError(response.error);
|
||||
} else if (response.token) {
|
||||
const shareUrl = `/${response.token}/${row.original.id}`;
|
||||
const newTab = window.open(shareUrl, "_blank");
|
||||
if (newTab) {
|
||||
newTab.focus();
|
||||
} else {
|
||||
router.push(`/${token}/${row.original.id}`);
|
||||
router.push(shareUrl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user