diff --git a/packages/hoppscotch-backend/prisma/migrations/20260506090000_local_auth/migration.sql b/packages/hoppscotch-backend/prisma/migrations/20260506090000_local_auth/migration.sql new file mode 100644 index 00000000..1488460e --- /dev/null +++ b/packages/hoppscotch-backend/prisma/migrations/20260506090000_local_auth/migration.sql @@ -0,0 +1,21 @@ +-- Add local username/password authentication support. +ALTER TABLE "User" ADD COLUMN "username" TEXT; + +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); + +CREATE TABLE "LocalCredential" ( + "id" TEXT NOT NULL, + "userUid" TEXT NOT NULL, + "passwordHash" TEXT NOT NULL, + "createdOn" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedOn" TIMESTAMPTZ(3) NOT NULL, + + CONSTRAINT "LocalCredential_pkey" PRIMARY KEY ("id") +); + +CREATE UNIQUE INDEX "LocalCredential_userUid_key" ON "LocalCredential"("userUid"); + +ALTER TABLE "LocalCredential" +ADD CONSTRAINT "LocalCredential_userUid_fkey" +FOREIGN KEY ("userUid") REFERENCES "User"("uid") +ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/hoppscotch-backend/prisma/schema.prisma b/packages/hoppscotch-backend/prisma/schema.prisma index 26a3b263..8d45a576 100644 --- a/packages/hoppscotch-backend/prisma/schema.prisma +++ b/packages/hoppscotch-backend/prisma/schema.prisma @@ -94,6 +94,7 @@ model TeamEnvironment { model User { uid String @id @default(cuid()) + username String? @unique displayName String? email String? @unique photoURL String? @@ -104,6 +105,7 @@ model User { createdOn DateTime @default(now()) @db.Timestamptz(3) lastLoggedOn DateTime? @db.Timestamptz(3) lastActiveOn DateTime? @db.Timestamptz(3) + localCredential LocalCredential? providerAccounts Account[] invitedUsers InvitedUsers[] mockServers MockServer[] @@ -117,6 +119,15 @@ model User { VerificationToken VerificationToken[] } +model LocalCredential { + id String @id @default(cuid()) + userUid String @unique + passwordHash String + createdOn DateTime @default(now()) @db.Timestamptz(3) + updatedOn DateTime @updatedAt @db.Timestamptz(3) + user User @relation(fields: [userUid], references: [uid], onDelete: Cascade) +} + model Account { id String @id @default(cuid()) userId String diff --git a/packages/hoppscotch-backend/src/user/user.model.ts b/packages/hoppscotch-backend/src/user/user.model.ts index 4cec5ce2..ff5dd47a 100644 --- a/packages/hoppscotch-backend/src/user/user.model.ts +++ b/packages/hoppscotch-backend/src/user/user.model.ts @@ -7,6 +7,12 @@ export class User { }) uid: string; + @Field({ + nullable: true, + description: 'Username of the user', + }) + username?: string; + @Field({ nullable: true, description: 'Name of the user (if fetched)',