Something went wrong. Try again.
A fork of @slices.network/slices forked from slices.network/slices
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { AtProtoClient } from "../generated_client.ts";import { logger } from "./logger.ts";import { SYSTEM_SLICE_URI, SYSTEM_SLICE_DID, DEFAULT_API_URL } from "./constants.ts";
export interface WaitlistCheckResult { hasAccess: boolean; isOnWaitlist: boolean;}
export async function checkUserWaitlistAccess( userDid: string, apiUrl = DEFAULT_API_URL): Promise<WaitlistCheckResult> { try { // Create a public client for checking waitlist status (no auth needed) const client = new AtProtoClient(apiUrl, SYSTEM_SLICE_URI);
// Query for invites for this DID - using json field to query the record content const invitesResult = await client.network.slices.waitlist.invite.getRecords({ where: { did: { eq: SYSTEM_SLICE_DID }, slice: { eq: SYSTEM_SLICE_URI }, json: { contains: userDid }, }, limit: 1, });
// Check if user has a valid invite if (invitesResult.records && invitesResult.records.length > 0) { const invite = invitesResult.records[0];
// Check if invite has expired if (invite.value.expiresAt) { const expiresAt = new Date(invite.value.expiresAt); const now = new Date(); if (expiresAt < now) { return { hasAccess: false, isOnWaitlist: false }; // Invite has expired } }
return { hasAccess: true, isOnWaitlist: false }; // Valid invite found }
// Check if user is already on the waitlist - requests are created by the user so record.did is correct const requestsResult = await client.network.slices.waitlist.request.getRecords({ where: { slice: { eq: SYSTEM_SLICE_URI }, json: { eq: userDid }, }, limit: 1, });
const isOnWaitlist = requestsResult.records && requestsResult.records.length > 0;
return { hasAccess: false, isOnWaitlist }; } catch (error) { logger.error("Error checking user waitlist access:", error); return { hasAccess: false, isOnWaitlist: false }; // Default to blocking access on error }}
export function showWaitlistError( userDid: string, isOnWaitlist: boolean): void { console.error("\n❌ Access Denied"); console.error("─".repeat(50));
if (isOnWaitlist) { console.error("You are already on the waitlist for Slices."); console.error("Please wait for an invitation to be sent to your account."); } else { console.error("You need an invitation to use Slices."); console.error("Please visit https://slices.network to request access."); }
console.error(`\nYour DID: ${userDid}`); console.error("─".repeat(50)); console.error( "If you believe this is an error, please DM @slices.network on Bsky.\n" );}