-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update auth to better-auth v1 #71
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "@repo/typescript-config/base.json", | ||
"include": ["src", "*.ts"], | ||
"exclude": ["node_modules"] | ||
"exclude": ["node_modules"], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Warnings: | ||
|
||
- You are about to drop the column `expiresAt` on the `account` table. All the data in the column will be lost. | ||
- A unique constraint covering the columns `[token]` on the table `session` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `createdAt` to the `account` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `updatedAt` to the `account` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `createdAt` to the `session` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `token` to the `session` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `updatedAt` to the `session` table without a default value. This is not possible if the table is not empty. | ||
Comment on lines
+4
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration adds multiple required columns ( Consider modifying the migration to handle existing data: - ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL,
- ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL
+ ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||
|
||
*/ | ||
-- AlterTable | ||
ALTER TABLE "account" DROP COLUMN "expiresAt", | ||
ADD COLUMN "accessTokenExpiresAt" TIMESTAMP(3), | ||
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL, | ||
ADD COLUMN "refreshTokenExpiresAt" TIMESTAMP(3), | ||
ADD COLUMN "scope" TEXT, | ||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; | ||
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Data loss warning: The migration script shows that the
Suggested actions:
🔗 Analysis chainVerify data migration for removed The Let me check the migration history to understand if this is a new table or if there's existing data that needs migration. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check if there's existing data in the expiresAt column that needs migration
echo "Checking for existing expiration data..."
ast-grep --pattern 'expiresAt' # Look for usages in the codebase
rg -l "expiresAt" # Find files referencing this column
Length of output: 324 Script: #!/bin/bash
# Check the previous migration that introduced the expiresAt column
cat packages/database/prisma/migrations/20241110144439_auth/migration.sql
# Check if there are any data migrations in the current migration
cat packages/database/prisma/migrations/20241126154111_final_auth/migration.sql
Length of output: 3275 |
||
|
||
-- AlterTable | ||
ALTER TABLE "session" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL, | ||
ADD COLUMN "token" TEXT NOT NULL, | ||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "verification" ADD COLUMN "updatedAt" TIMESTAMP(3), | ||
ALTER COLUMN "createdAt" DROP NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "session_token_key" ON "session"("token"); |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,8 +17,8 @@ model User { | |||||||||
image String? | ||||||||||
createdAt DateTime | ||||||||||
updatedAt DateTime | ||||||||||
accounts Account[] | ||||||||||
sessions Session[] | ||||||||||
accounts Account[] | ||||||||||
|
||||||||||
@@unique([email]) | ||||||||||
@@map("user") | ||||||||||
|
@@ -27,35 +27,44 @@ model User { | |||||||||
model Session { | ||||||||||
id String @id | ||||||||||
expiresAt DateTime | ||||||||||
token String | ||||||||||
createdAt DateTime | ||||||||||
updatedAt DateTime | ||||||||||
ipAddress String? | ||||||||||
userAgent String? | ||||||||||
userId String | ||||||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||||||||||
|
||||||||||
@@unique([token]) | ||||||||||
@@map("session") | ||||||||||
} | ||||||||||
|
||||||||||
model Account { | ||||||||||
id String @id | ||||||||||
accountId String | ||||||||||
providerId String | ||||||||||
userId String | ||||||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||||||||||
accessToken String? | ||||||||||
refreshToken String? | ||||||||||
idToken String? | ||||||||||
expiresAt DateTime? | ||||||||||
password String? | ||||||||||
id String @id | ||||||||||
accountId String | ||||||||||
providerId String | ||||||||||
userId String | ||||||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||||||||||
accessToken String? | ||||||||||
refreshToken String? | ||||||||||
idToken String? | ||||||||||
accessTokenExpiresAt DateTime? | ||||||||||
refreshTokenExpiresAt DateTime? | ||||||||||
scope String? | ||||||||||
password String? | ||||||||||
createdAt DateTime | ||||||||||
updatedAt DateTime | ||||||||||
|
||||||||||
@@map("account") | ||||||||||
} | ||||||||||
|
||||||||||
model Verification { | ||||||||||
id String @id | ||||||||||
id String @id | ||||||||||
identifier String | ||||||||||
value String | ||||||||||
expiresAt DateTime | ||||||||||
createdAt DateTime | ||||||||||
createdAt DateTime? | ||||||||||
updatedAt DateTime? | ||||||||||
Comment on lines
+66
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enforce timestamp consistency Making model Verification {
id String @id
identifier String
value String
expiresAt DateTime
- createdAt DateTime?
- updatedAt DateTime?
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
@@map("verification")
} 📝 Committable suggestion
Suggested change
|
||||||||||
|
||||||||||
@@map("verification") | ||||||||||
} | ||||||||||
|
@@ -65,5 +74,4 @@ model Trigger { | |||||||||
name String | ||||||||||
email String | ||||||||||
emailVerified Boolean | ||||||||||
|
||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,6 @@ | |
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"target": "ES2022" | ||
"target": "ES2022", | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling and improve user experience
The current implementation lacks error handling and forces a page reload.