fix(auth): migrate from next-auth to better-auth (#1453)
This commit is contained in:
parent
453f5bb3e6
commit
b4f595a68c
40 changed files with 668 additions and 390 deletions
49
lib/db/migrations/0010_better_auth.sql
Normal file
49
lib/db/migrations/0010_better_auth.sql
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "name" text;
|
||||
ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "emailVerified" boolean NOT NULL DEFAULT false;
|
||||
ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "image" text;
|
||||
ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "isAnonymous" boolean NOT NULL DEFAULT false;
|
||||
ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "createdAt" timestamp DEFAULT now() NOT NULL;
|
||||
ALTER TABLE "User" ADD COLUMN IF NOT EXISTS "updatedAt" timestamp DEFAULT now() NOT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "Session" (
|
||||
"id" text PRIMARY KEY,
|
||||
"expiresAt" timestamp NOT NULL,
|
||||
"token" text NOT NULL UNIQUE,
|
||||
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||||
"updatedAt" timestamp DEFAULT now() NOT NULL,
|
||||
"ipAddress" text,
|
||||
"userAgent" text,
|
||||
"userId" uuid NOT NULL REFERENCES "User"("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "Account" (
|
||||
"id" text PRIMARY KEY,
|
||||
"accountId" text NOT NULL,
|
||||
"providerId" text NOT NULL,
|
||||
"userId" uuid NOT NULL REFERENCES "User"("id") ON DELETE CASCADE,
|
||||
"accessToken" text,
|
||||
"refreshToken" text,
|
||||
"idToken" text,
|
||||
"accessTokenExpiresAt" timestamp,
|
||||
"refreshTokenExpiresAt" timestamp,
|
||||
"scope" text,
|
||||
"password" text,
|
||||
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||||
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "Verification" (
|
||||
"id" text PRIMARY KEY,
|
||||
"identifier" text NOT NULL,
|
||||
"value" text NOT NULL,
|
||||
"expiresAt" timestamp NOT NULL,
|
||||
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||||
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
UPDATE "User" SET "isAnonymous" = true WHERE email ~ '^guest-\d+$';
|
||||
|
||||
INSERT INTO "Account" ("id", "accountId", "providerId", "userId", "password", "createdAt", "updatedAt")
|
||||
SELECT gen_random_uuid()::text, id::text, 'credential', id, password, now(), now()
|
||||
FROM "User" WHERE password IS NOT NULL
|
||||
ON CONFLICT DO NOTHING;
|
||||
Loading…
Add table
Add a link
Reference in a new issue