From ac02b7b90115327f5bc9c20a5b28ea5241ee78ca Mon Sep 17 00:00:00 2001 From: Polaris Date: Tue, 23 Jul 2024 17:29:07 -0400 Subject: [PATCH] added comments --- app/(sharing)/[token]/[id]/page.tsx | 1 + app/(sharing)/[token]/token.ts | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/(sharing)/[token]/[id]/page.tsx b/app/(sharing)/[token]/[id]/page.tsx index a497355..f93fc07 100644 --- a/app/(sharing)/[token]/[id]/page.tsx +++ b/app/(sharing)/[token]/[id]/page.tsx @@ -13,6 +13,7 @@ type chunithm = chuni_score_playlog & export default async function Share({ params, }: { + // pass the token and playlog id as params params: { token: string; id: string }; }) { const { token, id } = params; diff --git a/app/(sharing)/[token]/token.ts b/app/(sharing)/[token]/token.ts index c64a064..8450e18 100644 --- a/app/(sharing)/[token]/token.ts +++ b/app/(sharing)/[token]/token.ts @@ -7,9 +7,9 @@ import { randomBytes } from "crypto"; import { redirect } from "next/navigation"; export async function generateShareToken(id: number): Promise<{ - token?: string; - id?: string; - error?: string; + token?: string; // share token + id?: string; // playlog id after the token + error?: string; // error }> { const { user } = await getAuth(); @@ -18,15 +18,17 @@ export async function generateShareToken(id: number): Promise<{ error: "Invalid user or user ID", }; } - + // generate the token that expires const gernatetoken = randomBytes(5).readUInt32BE(0).toString(); + + // generate token logic const token = await daphnis.linkSharingToken.create({ data: { - playlogId: id, - id: randomUUID(), - userId: user.id, - token: gernatetoken, - createdAt: new Date(), + playlogId: id, // sets the playlog id + id: randomUUID(), // generates a random share id + userId: user.id, // attaches the userid + token: gernatetoken, // makes an expirable token + createdAt: new Date(), // created at date }, });