From 6bf995e724eb83b7be169a23771de3ae8812873d Mon Sep 17 00:00:00 2001 From: Koffe <78866073+ThatKoffe@users.noreply.github.com> Date: Wed, 6 Dec 2023 10:56:19 +0100 Subject: [PATCH 1/2] Show error when not logged in instead of showing "login required" --- src/lib/components/cards/botCard.svelte | 4 ++-- src/routes/bots/[bot_id]/vote/+page.server.ts | 23 +++++++++---------- src/routes/bots/[bot_id]/vote/+page.svelte | 6 ++++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/lib/components/cards/botCard.svelte b/src/lib/components/cards/botCard.svelte index d57dfa1..a76799a 100644 --- a/src/lib/components/cards/botCard.svelte +++ b/src/lib/components/cards/botCard.svelte @@ -86,11 +86,11 @@ padding-bottom: 5px; } - .bot-info-item:not(:last-child) { + /* .bot-info-item:not(:last-child) { overflow: hidden; text-overflow: ellipsis; padding-bottom: 5px; - } + } */ .bot-tagline { /* auto line break */ diff --git a/src/routes/bots/[bot_id]/vote/+page.server.ts b/src/routes/bots/[bot_id]/vote/+page.server.ts index 56c030a..839fa43 100644 --- a/src/routes/bots/[bot_id]/vote/+page.server.ts +++ b/src/routes/bots/[bot_id]/vote/+page.server.ts @@ -1,4 +1,3 @@ -import requireActor from '$lib/server/middleware/requireActor.js'; import prisma from '$lib/server/prisma'; import SafeBot from '$lib/structures/bot'; import { BotApprovalStatus } from '@prisma/client'; @@ -7,8 +6,6 @@ import { error } from '@sveltejs/kit'; export const _voteTimeout = 1000 * 60 * 60 * 12; // 12 hours export async function load({ locals, params }) { - await requireActor(locals); - const bot = await prisma.bot.findUnique({ where: { id: params.bot_id @@ -25,15 +22,17 @@ export async function load({ locals, params }) { if (bot?.approval_status !== BotApprovalStatus.APPROVED) votingDisabled = true; - const latestVote = await prisma.botVote.findFirst({ - where: { - bot_id: bot.id, - voter_id: locals.actor!.id - }, - orderBy: { - created_time: 'desc' - } - }); + let latestVote = locals.actor + ? await prisma.botVote.findFirst({ + where: { + bot_id: bot.id, + voter_id: locals.actor!.id + }, + orderBy: { + created_time: 'desc' + } + }) + : null; if (latestVote) { if (Date.now() - latestVote.created_time.getTime() < _voteTimeout) { diff --git a/src/routes/bots/[bot_id]/vote/+page.svelte b/src/routes/bots/[bot_id]/vote/+page.svelte index dfaf33d..29e644a 100644 --- a/src/routes/bots/[bot_id]/vote/+page.svelte +++ b/src/routes/bots/[bot_id]/vote/+page.svelte @@ -16,6 +16,10 @@ errorMessage = 'Voting is currently disabled for this bot.'; } + if(!data?.actor){ + errorMessage = 'You must be logged in to vote for a bot.'; + } + function onVote() { loading = true; @@ -78,7 +82,7 @@