From 57d0b36781165caef8bc538d32deac9295cc98e3 Mon Sep 17 00:00:00 2001 From: Mackenzie Wildman Date: Wed, 28 Jun 2023 11:05:36 -0700 Subject: [PATCH 1/4] update db to input twitter auth response fields see https://next-auth.js.org/providers/twitter --- .../20230628180451_twitter_auth_fields/migration.sql | 3 +++ prisma/schema.prisma | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 prisma/migrations/20230628180451_twitter_auth_fields/migration.sql diff --git a/prisma/migrations/20230628180451_twitter_auth_fields/migration.sql b/prisma/migrations/20230628180451_twitter_auth_fields/migration.sql new file mode 100644 index 0000000..684ea5c --- /dev/null +++ b/prisma/migrations/20230628180451_twitter_auth_fields/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "Account" ADD COLUMN "oauth_token" TEXT, +ADD COLUMN "oauth_token_secret" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e1461d9..0f23527 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -16,6 +16,8 @@ model Account { providerAccountId String refresh_token String? @db.Text access_token String? @db.Text + oauth_token String? @db.Text + oauth_token_secret String? @db.Text expires_at Int? token_type String? scope String? From f80826d492550796acf588a7e91c4f645b27780a Mon Sep 17 00:00:00 2001 From: Mackenzie Wildman Date: Wed, 28 Jun 2023 11:06:07 -0700 Subject: [PATCH 2/4] login with twitter button --- src/app/login/Login.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/login/Login.tsx b/src/app/login/Login.tsx index 47a7b37..af3bc5d 100644 --- a/src/app/login/Login.tsx +++ b/src/app/login/Login.tsx @@ -14,7 +14,13 @@ export default function Login() { className='rounded-lg px-20 py-3 bg-cta text-black hover:opacity-80 transition' onClick={() => signIn('google')} > - Continue with Google + Sign in with Google + + ); From d4836d20a9c4fce164740769214f5f75050c2d7d Mon Sep 17 00:00:00 2001 From: Mackenzie Wildman Date: Wed, 28 Jun 2023 11:08:16 -0700 Subject: [PATCH 3/4] add twitter credentials to readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a83745f..0f4d558 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ Create a `.env` file at the root of the project. Add the following environment v GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= +# setup SSO with Twitter +TWITTER_CLIENT_ID= +TWITTER_CLIENT_SECRET= + # database DATABASE_URL=postgres://postgres:holaplex@localhost:5432/hub-starter POSTGRES_DB=hub-starter From d74ce9b7dcc0cc91b899b66797ba1a7cfc710f21 Mon Sep 17 00:00:00 2001 From: Mackenzie Wildman Date: Wed, 28 Jun 2023 11:12:49 -0700 Subject: [PATCH 4/4] update env var names to match what twitter gives --- README.md | 4 ++-- src/pages/api/auth/[...nextauth].ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f4d558..1b9cfe2 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= # setup SSO with Twitter -TWITTER_CLIENT_ID= -TWITTER_CLIENT_SECRET= +TWITTER_API_KEY= +TWITTER_API_KEY_SECRET= # database DATABASE_URL=postgres://postgres:holaplex@localhost:5432/hub-starter diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts index 3bd20d9..4e83500 100644 --- a/src/pages/api/auth/[...nextauth].ts +++ b/src/pages/api/auth/[...nextauth].ts @@ -1,5 +1,6 @@ import NextAuth from "next-auth"; import GoogleProvider from "next-auth/providers/google"; +import TwitterProvider from "next-auth/providers/twitter"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import type { NextAuthOptions } from "next-auth"; import prisma from "@/modules/db"; @@ -74,6 +75,10 @@ export const authOptions: NextAuthOptions = { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }), + TwitterProvider({ + clientId: process.env.TWITTER_API_KEY as string, + clientSecret: process.env.TWITTER_API_KEY_SECRET as string, + }) ], events: { async createUser({ user }) {