Add Flutter auth sessions to teams
All checks were successful
Build Docker Image / build (push) Successful in 2m10s

This commit is contained in:
Ruslan Bakiev
2026-05-31 16:46:04 +05:00
parent dd99bbe2e7
commit e6e014ebb0
4 changed files with 328 additions and 66 deletions

View File

@@ -0,0 +1,40 @@
-- CreateTable
CREATE TABLE "teams_app_loginchallenge" (
"id" SERIAL NOT NULL,
"uuid" TEXT NOT NULL,
"phone" VARCHAR(50) NOT NULL,
"code" VARCHAR(20) NOT NULL,
"expires_at" TIMESTAMP(3) NOT NULL,
"used_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "teams_app_loginchallenge_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "teams_app_authsession" (
"id" SERIAL NOT NULL,
"token" VARCHAR(255) NOT NULL,
"user_id" INTEGER NOT NULL,
"expires_at" TIMESTAMP(3) NOT NULL,
"revoked_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "teams_app_authsession_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "teams_app_loginchallenge_uuid_key" ON "teams_app_loginchallenge"("uuid");
-- CreateIndex
CREATE INDEX "teams_app_loginchallenge_phone_idx" ON "teams_app_loginchallenge"("phone");
-- CreateIndex
CREATE UNIQUE INDEX "teams_app_authsession_token_key" ON "teams_app_authsession"("token");
-- CreateIndex
CREATE INDEX "teams_app_authsession_user_id_idx" ON "teams_app_authsession"("user_id");
-- AddForeignKey
ALTER TABLE "teams_app_authsession" ADD CONSTRAINT "teams_app_authsession_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth_user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -8,20 +8,20 @@ datasource db {
}
model Team {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
name String @db.VarChar(200)
teamType String @default("BUYER") @map("team_type") @db.VarChar(20)
logtoOrgId String? @map("logto_org_id") @db.VarChar(100)
ownerId Int? @map("owner_id")
owner User? @relation(fields: [ownerId], references: [id])
selectedLocationType String? @map("selected_location_type") @db.VarChar(20)
selectedLocationUuid String? @map("selected_location_uuid") @db.VarChar(100)
selectedLocationName String? @map("selected_location_name") @db.VarChar(255)
selectedLocationLat Float? @map("selected_location_lat")
selectedLocationLon Float? @map("selected_location_lon")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
name String @db.VarChar(200)
teamType String @default("BUYER") @map("team_type") @db.VarChar(20)
logtoOrgId String? @map("logto_org_id") @db.VarChar(100)
ownerId Int? @map("owner_id")
owner User? @relation(fields: [ownerId], references: [id])
selectedLocationType String? @map("selected_location_type") @db.VarChar(20)
selectedLocationUuid String? @map("selected_location_uuid") @db.VarChar(100)
selectedLocationName String? @map("selected_location_name") @db.VarChar(255)
selectedLocationLat Float? @map("selected_location_lat")
selectedLocationLon Float? @map("selected_location_lon")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
members TeamMember[]
invitations TeamInvitation[]
@@ -32,40 +32,67 @@ model Team {
}
model User {
id Int @id @default(autoincrement())
password String @default("") @db.VarChar(128)
username String @unique @db.VarChar(150)
firstName String @default("") @map("first_name") @db.VarChar(150)
lastName String @default("") @map("last_name") @db.VarChar(150)
email String @default("") @db.VarChar(254)
isActive Boolean @default(true) @map("is_active")
dateJoined DateTime @default(now()) @map("date_joined")
isSuperuser Boolean @default(false) @map("is_superuser")
isStaff Boolean @default(false) @map("is_staff")
lastLogin DateTime? @map("last_login")
id Int @id @default(autoincrement())
password String @default("") @db.VarChar(128)
username String @unique @db.VarChar(150)
firstName String @default("") @map("first_name") @db.VarChar(150)
lastName String @default("") @map("last_name") @db.VarChar(150)
email String @default("") @db.VarChar(254)
isActive Boolean @default(true) @map("is_active")
dateJoined DateTime @default(now()) @map("date_joined")
isSuperuser Boolean @default(false) @map("is_superuser")
isStaff Boolean @default(false) @map("is_staff")
lastLogin DateTime? @map("last_login")
profile UserProfile?
teams Team[]
profile UserProfile?
sessions AuthSession[]
teams Team[]
memberships TeamMember[]
@@map("auth_user")
}
model UserProfile {
id Int @id @default(autoincrement())
userId Int @unique @map("user_id")
user User @relation(fields: [userId], references: [id])
logtoId String @unique @map("logto_id") @db.VarChar(255)
avatarId String? @map("avatar_id") @db.VarChar(255)
phone String @default("") @db.VarChar(50)
activeTeamId Int? @map("active_team_id")
activeTeam Team? @relation("ActiveTeam", fields: [activeTeamId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
id Int @id @default(autoincrement())
userId Int @unique @map("user_id")
user User @relation(fields: [userId], references: [id])
logtoId String @unique @map("logto_id") @db.VarChar(255)
avatarId String? @map("avatar_id") @db.VarChar(255)
phone String @default("") @db.VarChar(50)
activeTeamId Int? @map("active_team_id")
activeTeam Team? @relation("ActiveTeam", fields: [activeTeamId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("teams_app_userprofile")
}
model LoginChallenge {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
phone String @db.VarChar(50)
code String @db.VarChar(20)
expiresAt DateTime @map("expires_at")
usedAt DateTime? @map("used_at")
createdAt DateTime @default(now()) @map("created_at")
@@index([phone])
@@map("teams_app_loginchallenge")
}
model AuthSession {
id Int @id @default(autoincrement())
token String @unique @db.VarChar(255)
userId Int @map("user_id")
user User @relation(fields: [userId], references: [id])
expiresAt DateTime @map("expires_at")
revokedAt DateTime? @map("revoked_at")
createdAt DateTime @default(now()) @map("created_at")
@@index([userId])
@@map("teams_app_authsession")
}
model TeamMember {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
@@ -81,16 +108,16 @@ model TeamMember {
}
model TeamInvitation {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
teamId Int @map("team_id")
team Team @relation(fields: [teamId], references: [id])
email String @db.VarChar(254)
role String @default("MEMBER") @db.VarChar(20)
status String @default("PENDING") @db.VarChar(20)
invitedBy String @default("") @map("invited_by") @db.VarChar(255)
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
teamId Int @map("team_id")
team Team @relation(fields: [teamId], references: [id])
email String @db.VarChar(254)
role String @default("MEMBER") @db.VarChar(20)
status String @default("PENDING") @db.VarChar(20)
invitedBy String @default("") @map("invited_by") @db.VarChar(255)
expiresAt DateTime? @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
createdAt DateTime @default(now()) @map("created_at")
tokens TeamInvitationToken[]
@@ -99,14 +126,14 @@ model TeamInvitation {
}
model TeamInvitationToken {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
invitationId Int @map("invitation_id")
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
invitationId Int @map("invitation_id")
invitation TeamInvitation @relation(fields: [invitationId], references: [id])
tokenHash String @unique @map("token_hash") @db.VarChar(255)
workflowStatus String @default("pending") @map("workflow_status") @db.VarChar(20)
expiresAt DateTime? @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
tokenHash String @unique @map("token_hash") @db.VarChar(255)
workflowStatus String @default("pending") @map("workflow_status") @db.VarChar(20)
expiresAt DateTime? @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
@@map("teams_app_teaminvitationtoken")
}