Skip to content

Random createPasswordResetToken called #44

@laihuynhnhatminh

Description

@laihuynhnhatminh

There is a random createPasswordResetToken called inside reset-tokens.ts file. Is this a typo error? @webdevcody

createPasswordResetToken;

import { TOKEN_LENGTH, TOKEN_TTL } from "@/app-config";
import { generateRandomToken } from "@/data-access/utils";
import { database } from "@/db";
import { resetTokens } from "@/db/schema";
import { UserId } from "@/use-cases/types";
import { eq } from "drizzle-orm";

export async function createPasswordResetToken(userId: UserId) {
  const token = await generateRandomToken(TOKEN_LENGTH);
  const tokenExpiresAt = new Date(Date.now() + TOKEN_TTL);

  await database
    .insert(resetTokens)
    .values({
      userId,
      token,
      tokenExpiresAt,
    })
    .onConflictDoUpdate({
      target: resetTokens.userId,
      set: {
        token,
        tokenExpiresAt,
      },
    });

  return token;
}

schema.ts line 212 -> 223
duplicated properties tokenExpiresAt: timestamp("tokenExpiresAt", { mode: "date" }).notNull(),

export const invites = pgTable("gf_invites", {
  id: serial("id").primaryKey(),
  token: text("token")
    .notNull()
    .default(sql`gen_random_uuid()`)
    .unique(),
  tokenExpiresAt: timestamp("tokenExpiresAt", { mode: "date" }),
  groupId: serial("groupId")
    .notNull()
    .references(() => groups.id, { onDelete: "cascade" }),
  tokenExpiresAt: timestamp("tokenExpiresAt", { mode: "date" }).notNull(),
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions