mirror of
https://github.com/polaroi8d/cactoide.git
synced 2026-03-22 14:15:28 +00:00
feat(tmp): invite link feature
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { database } from '$lib/database/db';
|
||||
import { events, rsvps } from '$lib/database/schema';
|
||||
import { eq, asc } from 'drizzle-orm';
|
||||
import { events, rsvps, inviteTokens } from '$lib/database/schema';
|
||||
import { eq, asc, and } from 'drizzle-orm';
|
||||
import { error, fail } from '@sveltejs/kit';
|
||||
import type { PageServerLoad, Actions } from './$types';
|
||||
import { isTokenValid } from '$lib/inviteTokenHelpers.js';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, cookies }) => {
|
||||
const eventId = params.id;
|
||||
@@ -25,6 +26,16 @@ export const load: PageServerLoad = async ({ params, cookies }) => {
|
||||
const event = eventData[0];
|
||||
const eventRsvps = rsvpData;
|
||||
|
||||
// Check if this is an invite-only event
|
||||
if (event.visibility === 'invite-only') {
|
||||
// For invite-only events, check if user is the event creator
|
||||
const userId = cookies.get('cactoideUserId');
|
||||
if (event.userId !== userId) {
|
||||
// User is not the creator, redirect to a message about needing invite
|
||||
throw error(403, 'This event requires an invite link to view');
|
||||
}
|
||||
}
|
||||
|
||||
// Transform the data to match the expected interface
|
||||
const transformedEvent = {
|
||||
id: event.id,
|
||||
@@ -85,6 +96,11 @@ export const actions: Actions = {
|
||||
return fail(404, { error: 'Event not found' });
|
||||
}
|
||||
|
||||
// Check if this is an invite-only event
|
||||
if (eventData.visibility === 'invite-only') {
|
||||
return fail(403, { error: 'This event requires an invite link to RSVP' });
|
||||
}
|
||||
|
||||
// Get current RSVPs
|
||||
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user