Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions packages/nextly/src/__tests__/database/_fixture-schema/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,39 +267,6 @@ export const nextlyTables: TableDefinition[] = [
],
},

{
name: "verification_tokens",
comment: "Email verification tokens - Auth.js v5 compatible",
columns: [
{
name: "identifier",
type: "text",
nullable: false,
},
{
name: "token",
type: "text",
nullable: false,
},
{
name: "expires",
type: "timestamp",
nullable: false,
},
],
indexes: [
{
name: "verification_tokens_identifier_token_pk",
columns: ["identifier", "token"],
unique: true,
},
{
name: "verification_tokens_token_idx",
columns: ["token"],
},
],
},

{
name: "password_reset_tokens",
comment: "Password reset tokens with hashing for security",
Expand Down
8 changes: 0 additions & 8 deletions packages/nextly/src/__tests__/fixtures/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ function createTables(sqlite: Database.Database) {
CREATE UNIQUE INDEX IF NOT EXISTS evt_identifier_token_hash_unique ON email_verification_tokens(identifier, token_hash);
CREATE INDEX IF NOT EXISTS evt_expires_idx ON email_verification_tokens(expires);

CREATE TABLE IF NOT EXISTS verification_tokens (
identifier TEXT NOT NULL,
token TEXT NOT NULL,
expires INTEGER NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS verification_tokens_identifier_token_pk ON verification_tokens(identifier, token);
CREATE INDEX IF NOT EXISTS verification_tokens_token_idx ON verification_tokens(token);

CREATE TABLE IF NOT EXISTS user_roles (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
Expand Down
6 changes: 0 additions & 6 deletions packages/nextly/src/database/sqlite-core-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ export function generateSqliteCoreTableStatements(): string[] {
"user_id" TEXT NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
"expires" INTEGER NOT NULL
)`,
`CREATE TABLE IF NOT EXISTS "verification_tokens" (
"identifier" TEXT NOT NULL,
"token" TEXT NOT NULL,
"expires" INTEGER NOT NULL,
UNIQUE("identifier", "token")
)`,
`CREATE TABLE IF NOT EXISTS "password_reset_tokens" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"identifier" TEXT NOT NULL,
Expand Down
28 changes: 0 additions & 28 deletions packages/nextly/src/domains/auth/__tests__/auth-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,33 +932,5 @@ describe("AuthService", () => {
expect(allTokens).toHaveLength(1);
expect(allTokens[0].identifier).toBe(validEmail);
});

it("should delete expired Auth.js verification tokens", async () => {
// Arrange: Create expired and valid Auth.js verification tokens
const expiredEmail = "expired@test.com";
const validEmail = "valid@test.com";

// Create expired token
await testDb.db.insert(testDb.schema.verificationTokens).values({
identifier: expiredEmail,
token: "expired-authjs-token",
expires: new Date(Date.now() - 1000), // Expired
});

// Create valid token
await testDb.db.insert(testDb.schema.verificationTokens).values({
identifier: validEmail,
token: "valid-authjs-token",
expires: new Date(Date.now() + TOKEN_EXPIRY_HOURS * HOUR_IN_MS), // Valid for 24h
});

// Act
await service.cleanupExpiredTokens();

// Assert: Expired token deleted, valid token remains
const allTokens = await testDb.db.query.verificationTokens.findMany();
expect(allTokens).toHaveLength(1);
expect(allTokens[0].identifier).toBe(validEmail);
});
});
});
5 changes: 0 additions & 5 deletions packages/nextly/src/domains/auth/services/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,6 @@ export class AuthService extends BaseService {
await this.db
.delete(this.tables.emailVerificationTokens)
.where(lt(this.tables.emailVerificationTokens.expires, now));

// Auth.js verification tokens
await this.db
.delete(this.tables.verificationTokens)
.where(lt(this.tables.verificationTokens.expires, now));
} catch (error) {
console.error("Failed to cleanup expired tokens:", error);
}
Expand Down
1 change: 0 additions & 1 deletion packages/nextly/src/schemas/__tests__/public-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe("schemas public API", () => {
"users",
"accounts",
"sessions",
"verification_tokens",
"password_reset_tokens",
"email_verification_tokens",
"refresh_tokens",
Expand Down
1 change: 0 additions & 1 deletion packages/nextly/src/schemas/_dialect-bundles/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export {
} from "../users/mysql-relations";

export {
verificationTokens,
emailVerificationTokens,
passwordResetTokens,
refreshTokens,
Expand Down
1 change: 0 additions & 1 deletion packages/nextly/src/schemas/_dialect-bundles/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export {

// Auth tokens.
export {
verificationTokens,
emailVerificationTokens,
passwordResetTokens,
refreshTokens,
Expand Down
1 change: 0 additions & 1 deletion packages/nextly/src/schemas/_dialect-bundles/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export {
} from "../users/sqlite-relations";

export {
verificationTokens,
emailVerificationTokens,
passwordResetTokens,
refreshTokens,
Expand Down
3 changes: 0 additions & 3 deletions packages/nextly/src/schemas/auth-tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,18 @@ export function authTokenTables(dialect: SupportedDialect) {
switch (dialect) {
case "postgresql":
return {
verificationTokens: pg.verificationTokens,
emailVerificationTokens: pg.emailVerificationTokens,
passwordResetTokens: pg.passwordResetTokens,
refreshTokens: pg.refreshTokens,
};
case "mysql":
return {
verificationTokens: my.verificationTokens,
emailVerificationTokens: my.emailVerificationTokens,
passwordResetTokens: my.passwordResetTokens,
refreshTokens: my.refreshTokens,
};
case "sqlite":
return {
verificationTokens: sl.verificationTokens,
emailVerificationTokens: sl.emailVerificationTokens,
passwordResetTokens: sl.passwordResetTokens,
refreshTokens: sl.refreshTokens,
Expand Down
19 changes: 1 addition & 18 deletions packages/nextly/src/schemas/auth-tokens/mysql.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Auth-token tables — MySQL.
*
* Tables: verificationTokens, emailVerificationTokens, passwordResetTokens,
* refreshTokens.
* Tables: emailVerificationTokens, passwordResetTokens, refreshTokens.
* Moved verbatim from packages/nextly/src/database/schema/mysql.ts as part of
* Plan A schemas consolidation. No behavior change.
*
Expand All @@ -26,22 +25,6 @@ import {

import { users } from "../users/mysql";

export const verificationTokens = mysqlTable(
"verification_tokens",
{
identifier: varchar("identifier", { length: 191 }).notNull(),
token: varchar("token", { length: 191 }).notNull(),
expires: datetime("expires").notNull(),
},
t => [
uniqueIndex("verification_tokens_identifier_token_pk").on(
t.identifier,
t.token
),
index("verification_tokens_token_idx").on(t.token),
]
);

// Password reset tokens (custom table)
export const passwordResetTokens = mysqlTable(
"password_reset_tokens",
Expand Down
19 changes: 1 addition & 18 deletions packages/nextly/src/schemas/auth-tokens/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Auth-token tables — PostgreSQL.
*
* Tables: verificationTokens, emailVerificationTokens, passwordResetTokens,
* refreshTokens.
* Tables: emailVerificationTokens, passwordResetTokens, refreshTokens.
* Moved verbatim from packages/nextly/src/database/schema/postgres.ts as part
* of Plan A schemas consolidation. No behavior change.
*
Expand All @@ -26,22 +25,6 @@ import {

import { users } from "../users/postgres";

export const verificationTokens = pgTable(
"verification_tokens",
{
identifier: text("identifier").notNull(),
token: text("token").notNull(),
expires: timestamp("expires", { withTimezone: false }).notNull(),
},
t => [
uniqueIndex("verification_tokens_identifier_token_pk").on(
t.identifier,
t.token
),
index("verification_tokens_token_idx").on(t.token),
]
);

// Password reset tokens (custom table)
export const passwordResetTokens = pgTable(
"password_reset_tokens",
Expand Down
19 changes: 1 addition & 18 deletions packages/nextly/src/schemas/auth-tokens/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Auth-token tables — SQLite.
*
* Tables: verificationTokens, emailVerificationTokens, passwordResetTokens,
* refreshTokens.
* Tables: emailVerificationTokens, passwordResetTokens, refreshTokens.
* Moved verbatim from packages/nextly/src/database/schema/sqlite.ts as part of
* Plan A schemas consolidation. No behavior change.
*
Expand All @@ -24,22 +23,6 @@ import {

import { users } from "../users/sqlite";

export const verificationTokens = sqliteTable(
"verification_tokens",
{
identifier: text("identifier").notNull(),
token: text("token").notNull(),
expires: integer("expires", { mode: "timestamp" }).notNull(),
},
t => [
uniqueIndex("verification_tokens_identifier_token_pk").on(
t.identifier,
t.token
),
index("verification_tokens_token_idx").on(t.token),
]
);

// Password reset tokens (custom table)
export const passwordResetTokens = sqliteTable(
"password_reset_tokens",
Expand Down
2 changes: 0 additions & 2 deletions packages/nextly/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const CORE_TABLE_NAMES: readonly string[] = [
"users",
"accounts",
"sessions",
"verification_tokens",
"password_reset_tokens",
"email_verification_tokens",
"refresh_tokens",
Expand Down Expand Up @@ -187,7 +186,6 @@ export { users, accounts, sessions } from "./users/postgres";

// Plan A Task 6 — auth-token tables. PG re-exports for direct-query callers.
export {
verificationTokens,
emailVerificationTokens,
passwordResetTokens,
refreshTokens,
Expand Down
1 change: 0 additions & 1 deletion packages/nextly/src/types/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export interface AuthTables {
users: unknown;
accounts: unknown;
sessions: unknown;
verificationTokens: unknown;
passwordResetTokens: unknown;
emailVerificationTokens?: unknown;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/nextly/src/types/database-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ export interface AuthSchemaTables {
tokenHash: unknown;
expires: unknown;
};
verificationTokens: {
id?: unknown;
expires: unknown;
};
accounts: {
id: unknown;
userId: unknown;
Expand Down
Loading