From 281f8a0785052a5ced610ba10c88ec47094231fb Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:10:29 +0900 Subject: [PATCH 01/10] Update schema.sql Add unique and foreign key constraints to the schema --- packages/adapter-pg/schema.sql | 43 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/adapter-pg/schema.sql b/packages/adapter-pg/schema.sql index d1bd429c2e..8734ec3b6d 100644 --- a/packages/adapter-pg/schema.sql +++ b/packages/adapter-pg/schema.sql @@ -1,18 +1,20 @@ \set ON_ERROR_STOP true -CREATE TABLE verification_token +CREATE TABLE users ( - identifier TEXT NOT NULL, - expires TIMESTAMPTZ NOT NULL, - token TEXT NOT NULL, - - PRIMARY KEY (identifier, token) + id SERIAL, + name VARCHAR(255), + email VARCHAR(255) UNIQUE NOT NULL, + "emailVerified" TIMESTAMPTZ, + image TEXT, + + PRIMARY KEY (id) ); CREATE TABLE accounts ( id SERIAL, - "userId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, type VARCHAR(255) NOT NULL, provider VARCHAR(255) NOT NULL, "providerAccountId" VARCHAR(255) NOT NULL, @@ -23,27 +25,26 @@ CREATE TABLE accounts scope TEXT, session_state TEXT, token_type TEXT, - - PRIMARY KEY (id) + + PRIMARY KEY (id), + UNIQUE (provider, "providerAccountId") ); - + CREATE TABLE sessions ( id SERIAL, - "userId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, expires TIMESTAMPTZ NOT NULL, - "sessionToken" VARCHAR(255) NOT NULL, - + "sessionToken" VARCHAR(255) UNIQUE NOT NULL, + PRIMARY KEY (id) ); -CREATE TABLE users +CREATE TABLE verification_token ( - id SERIAL, - name VARCHAR(255), - email VARCHAR(255), - "emailVerified" TIMESTAMPTZ, - image TEXT, - - PRIMARY KEY (id) + identifier TEXT NOT NULL, + expires TIMESTAMPTZ NOT NULL, + token TEXT NOT NULL, + + PRIMARY KEY (identifier, token) ); From 5e70b4a95964f36ca98e8c9a4acb19144da7b91c Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:15:24 +0900 Subject: [PATCH 02/10] Update pg.mdx Add unique and foreign key contraints to the schema --- docs/pages/getting-started/adapters/pg.mdx | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/docs/pages/getting-started/adapters/pg.mdx b/docs/pages/getting-started/adapters/pg.mdx index 80ef5199f2..03505e1723 100644 --- a/docs/pages/getting-started/adapters/pg.mdx +++ b/docs/pages/getting-started/adapters/pg.mdx @@ -202,19 +202,21 @@ The SQL schema for the tables used by this adapter is as follows. Learn more abo doc page on [Database Models](/guides/creating-a-database-adapter). ```sql -CREATE TABLE verification_token +CREATE TABLE users ( - identifier TEXT NOT NULL, - expires TIMESTAMPTZ NOT NULL, - token TEXT NOT NULL, - - PRIMARY KEY (identifier, token) + id SERIAL, + name VARCHAR(255), + email VARCHAR(255) UNIQUE NOT NULL, + "emailVerified" TIMESTAMPTZ, + image TEXT, + + PRIMARY KEY (id) ); CREATE TABLE accounts ( id SERIAL, - "userId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, type VARCHAR(255) NOT NULL, provider VARCHAR(255) NOT NULL, "providerAccountId" VARCHAR(255) NOT NULL, @@ -225,29 +227,28 @@ CREATE TABLE accounts scope TEXT, session_state TEXT, token_type TEXT, - - PRIMARY KEY (id) + + PRIMARY KEY (id), + UNIQUE (provider, "providerAccountId") ); - + CREATE TABLE sessions ( id SERIAL, - "userId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, expires TIMESTAMPTZ NOT NULL, - "sessionToken" VARCHAR(255) NOT NULL, - + "sessionToken" VARCHAR(255) UNIQUE NOT NULL, + PRIMARY KEY (id) ); -CREATE TABLE users +CREATE TABLE verification_token ( - id SERIAL, - name VARCHAR(255), - email VARCHAR(255), - "emailVerified" TIMESTAMPTZ, - image TEXT, - - PRIMARY KEY (id) + identifier TEXT NOT NULL, + expires TIMESTAMPTZ NOT NULL, + token TEXT NOT NULL, + + PRIMARY KEY (identifier, token) ); ``` From 0dfa804d888df88f87880bdb4d670e7d3c2b9262 Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:55:40 +0900 Subject: [PATCH 03/10] Update schema.sql user's email may be NULL --- packages/adapter-pg/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-pg/schema.sql b/packages/adapter-pg/schema.sql index 8734ec3b6d..e451c21015 100644 --- a/packages/adapter-pg/schema.sql +++ b/packages/adapter-pg/schema.sql @@ -4,7 +4,7 @@ CREATE TABLE users ( id SERIAL, name VARCHAR(255), - email VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) UNIQUE, "emailVerified" TIMESTAMPTZ, image TEXT, From ae30bcebed78e536f3515710ac46f37fe2cee294 Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:57:22 +0900 Subject: [PATCH 04/10] Update pg.mdx user's email may be NULL --- docs/pages/getting-started/adapters/pg.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/getting-started/adapters/pg.mdx b/docs/pages/getting-started/adapters/pg.mdx index 03505e1723..51dddd2189 100644 --- a/docs/pages/getting-started/adapters/pg.mdx +++ b/docs/pages/getting-started/adapters/pg.mdx @@ -206,7 +206,7 @@ CREATE TABLE users ( id SERIAL, name VARCHAR(255), - email VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) UNIQUE, "emailVerified" TIMESTAMPTZ, image TEXT, From 23eab88133763154c15d6b49c34f055a11158494 Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:04:47 +0900 Subject: [PATCH 05/10] Update pg.mdx Bug fix --- docs/pages/getting-started/adapters/pg.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/pages/getting-started/adapters/pg.mdx b/docs/pages/getting-started/adapters/pg.mdx index 51dddd2189..cac20aaa4a 100644 --- a/docs/pages/getting-started/adapters/pg.mdx +++ b/docs/pages/getting-started/adapters/pg.mdx @@ -228,8 +228,7 @@ CREATE TABLE accounts session_state TEXT, token_type TEXT, - PRIMARY KEY (id), - UNIQUE (provider, "providerAccountId") + PRIMARY KEY (id) ); CREATE TABLE sessions From 4afb2a0651cab368c2b46b2523f9ea62f49d5d8b Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:05:18 +0900 Subject: [PATCH 06/10] Update schema.sql Bug fix --- packages/adapter-pg/schema.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/adapter-pg/schema.sql b/packages/adapter-pg/schema.sql index e451c21015..2c70d2db22 100644 --- a/packages/adapter-pg/schema.sql +++ b/packages/adapter-pg/schema.sql @@ -26,8 +26,7 @@ CREATE TABLE accounts session_state TEXT, token_type TEXT, - PRIMARY KEY (id), - UNIQUE (provider, "providerAccountId") + PRIMARY KEY (id) ); CREATE TABLE sessions From e646723adea8da26a7d5e5184a4ed718fb8d711c Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sat, 21 Dec 2024 16:29:37 +0900 Subject: [PATCH 07/10] Update schema.sql For some reason cascade delete does not work without explicitly writing the primary key (id) in the foreign key definition. --- packages/adapter-pg/schema.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/adapter-pg/schema.sql b/packages/adapter-pg/schema.sql index 2c70d2db22..cae70d49a7 100644 --- a/packages/adapter-pg/schema.sql +++ b/packages/adapter-pg/schema.sql @@ -14,7 +14,7 @@ CREATE TABLE users CREATE TABLE accounts ( id SERIAL, - "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, + "userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, type VARCHAR(255) NOT NULL, provider VARCHAR(255) NOT NULL, "providerAccountId" VARCHAR(255) NOT NULL, @@ -32,7 +32,7 @@ CREATE TABLE accounts CREATE TABLE sessions ( id SERIAL, - "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, + "userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, expires TIMESTAMPTZ NOT NULL, "sessionToken" VARCHAR(255) UNIQUE NOT NULL, From bdb89dfb39e24384a04dce0d3bc9f6f7cc653962 Mon Sep 17 00:00:00 2001 From: Baptiste L <54464650+baptiste00001@users.noreply.github.com> Date: Sat, 21 Dec 2024 16:30:27 +0900 Subject: [PATCH 08/10] Update pg.mdx For some reason cascade delete does not work without explicitly writing the primary key (id) in the foreign key definition. --- docs/pages/getting-started/adapters/pg.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/getting-started/adapters/pg.mdx b/docs/pages/getting-started/adapters/pg.mdx index cac20aaa4a..a19e8237ec 100644 --- a/docs/pages/getting-started/adapters/pg.mdx +++ b/docs/pages/getting-started/adapters/pg.mdx @@ -216,7 +216,7 @@ CREATE TABLE users CREATE TABLE accounts ( id SERIAL, - "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, + "userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, type VARCHAR(255) NOT NULL, provider VARCHAR(255) NOT NULL, "providerAccountId" VARCHAR(255) NOT NULL, @@ -234,7 +234,7 @@ CREATE TABLE accounts CREATE TABLE sessions ( id SERIAL, - "userId" INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, + "userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, expires TIMESTAMPTZ NOT NULL, "sessionToken" VARCHAR(255) UNIQUE NOT NULL, From 311ab0822c991e957f49b7ca6dc779ab7330cc51 Mon Sep 17 00:00:00 2001 From: Baptiste L Date: Sun, 22 Dec 2024 18:44:18 +0900 Subject: [PATCH 09/10] Remove spaces to pass prettier formatting check --- docs/pages/getting-started/adapters/pg.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/pages/getting-started/adapters/pg.mdx b/docs/pages/getting-started/adapters/pg.mdx index a19e8237ec..5558c945a4 100644 --- a/docs/pages/getting-started/adapters/pg.mdx +++ b/docs/pages/getting-started/adapters/pg.mdx @@ -209,7 +209,7 @@ CREATE TABLE users email VARCHAR(255) UNIQUE, "emailVerified" TIMESTAMPTZ, image TEXT, - + PRIMARY KEY (id) ); @@ -227,17 +227,17 @@ CREATE TABLE accounts scope TEXT, session_state TEXT, token_type TEXT, - + PRIMARY KEY (id) ); - + CREATE TABLE sessions ( id SERIAL, "userId" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE, expires TIMESTAMPTZ NOT NULL, "sessionToken" VARCHAR(255) UNIQUE NOT NULL, - + PRIMARY KEY (id) ); @@ -246,7 +246,7 @@ CREATE TABLE verification_token identifier TEXT NOT NULL, expires TIMESTAMPTZ NOT NULL, token TEXT NOT NULL, - + PRIMARY KEY (identifier, token) ); From 1559695cfcbd47a85834dac0b73adea444c867d8 Mon Sep 17 00:00:00 2001 From: Baptiste L Date: Sun, 22 Dec 2024 18:49:47 +0900 Subject: [PATCH 10/10] Remove extra space to pass prettier formatting check --- docs/pages/getting-started/providers/apple.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/getting-started/providers/apple.mdx b/docs/pages/getting-started/providers/apple.mdx index 1fbb0db8d1..e881ad717a 100644 --- a/docs/pages/getting-started/providers/apple.mdx +++ b/docs/pages/getting-started/providers/apple.mdx @@ -10,7 +10,7 @@ import { Code } from "@/components/Code" - Sign in with Apple [REST API](https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api) - [How to retrieve](https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple#3383773) the user's information from Apple ID servers -> **_NOTE:_** Apple currently does not support [RedirectProxyUrl](https://github.com/nextauthjs/next-auth/blob/3ec06842682a31e53fceabca701a362abda1e7dd/packages/core/src/lib/utils/providers.ts#L48) usage. +> **_NOTE:_** Apple currently does not support [RedirectProxyUrl](https://github.com/nextauthjs/next-auth/blob/3ec06842682a31e53fceabca701a362abda1e7dd/packages/core/src/lib/utils/providers.ts#L48) usage. ## Setup