From 930d875545ca12d78bc311ce2c14837ea17179a8 Mon Sep 17 00:00:00 2001
From: Security2431
Date: Thu, 4 Jan 2024 09:24:16 +0200
Subject: [PATCH] fix: add google provider for auth
---
.../src/app/_components/auth-showcase.tsx | 9 ++------
apps/nextjs/src/app/_components/button.tsx | 2 ++
.../nextjs/src/app/_components/form/Input.tsx | 2 +-
.../nextjs/src/app/_components/form/Label.tsx | 5 ++++-
apps/nextjs/src/components/auth.tsx | 21 ++++++++++++-------
packages/auth/index.ts | 15 ++++++++-----
6 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/apps/nextjs/src/app/_components/auth-showcase.tsx b/apps/nextjs/src/app/_components/auth-showcase.tsx
index b018e93f..afe607b1 100644
--- a/apps/nextjs/src/app/_components/auth-showcase.tsx
+++ b/apps/nextjs/src/app/_components/auth-showcase.tsx
@@ -12,10 +12,7 @@ export async function AuthShowcase({ provider }: Props) {
if (!session) {
return (
-
+
Sign in with {provider.charAt(0).toUpperCase() + provider.slice(1)}
);
@@ -27,9 +24,7 @@ export async function AuthShowcase({ provider }: Props) {
{session && Logged in as {session.user.name}}
-
- Sign out
-
+ Sign out
);
}
diff --git a/apps/nextjs/src/app/_components/button.tsx b/apps/nextjs/src/app/_components/button.tsx
index 13e47bfd..0e213f27 100644
--- a/apps/nextjs/src/app/_components/button.tsx
+++ b/apps/nextjs/src/app/_components/button.tsx
@@ -37,6 +37,8 @@ const Button = forwardRef[(
{
"border border-white bg-transparent px-4 py-2 text-white no-underline hover:border-transparent hover:bg-white hover:text-purple-500":
variant === "primary",
+ "rounded-full bg-white/10 px-10 py-3 font-semibold no-underline transition hover:bg-white/20":
+ variant === "secondary",
"p-0 text-white hover:underline": variant === "link",
},
className,
diff --git a/apps/nextjs/src/app/_components/form/Input.tsx b/apps/nextjs/src/app/_components/form/Input.tsx
index 7eb71b0d..fc456243 100644
--- a/apps/nextjs/src/app/_components/form/Input.tsx
+++ b/apps/nextjs/src/app/_components/form/Input.tsx
@@ -13,7 +13,7 @@ type Props = InputHTMLAttributes;
/*
============================================================================= */
const Input = forwardRef][(
- ({ onClick, className, type, ...props }, ref) => (
+ ({ onClick, className, type = "text", ...props }, ref) => (
(
),
diff --git a/apps/nextjs/src/components/auth.tsx b/apps/nextjs/src/components/auth.tsx
index 0def0b59..6eac4b07 100644
--- a/apps/nextjs/src/components/auth.tsx
+++ b/apps/nextjs/src/components/auth.tsx
@@ -1,24 +1,31 @@
-import type { ComponentProps } from "react";
-
import type { OAuthProviders } from "@acme/auth";
import { CSRF_experimental } from "@acme/auth";
+import Button from "~/app/_components/button";
+
export function SignIn({
provider,
...props
-}: { provider: OAuthProviders } & ComponentProps<"button">) {
+}: {
+ provider: OAuthProviders;
+ children: React.ReactNode;
+}) {
return (
);
}
-export function SignOut(props: ComponentProps<"button">) {
+export function SignOut(props: { children: React.ReactNode }) {
return (
-
);
diff --git a/packages/auth/index.ts b/packages/auth/index.ts
index 42e76f59..a94799f2 100644
--- a/packages/auth/index.ts
+++ b/packages/auth/index.ts
@@ -1,5 +1,5 @@
import Github from "@auth/core/providers/github";
-// import Google from "@auth/core/providers/google";
+import Google from "@auth/core/providers/google";
import type { DefaultSession } from "@auth/core/types";
import { PrismaAdapter } from "@auth/prisma-adapter";
import NextAuth from "next-auth";
@@ -28,14 +28,19 @@ export const {
CSRF_experimental,
} = NextAuth({
adapter: PrismaAdapter(prisma),
+ secret: env.NEXTAUTH_SECRET,
providers: [
- // Google({
- // clientId: env.GOOGLE_CLIENT_ID,
- // clientSecret: env.GOOGLE_CLIENT_SECRET,
- // }),
+ Google({
+ clientId: env.GOOGLE_CLIENT_ID,
+ clientSecret: env.GOOGLE_CLIENT_SECRET,
+ // NextJS is able to automatically link accounts. See the discussion thread:
+ // https://github.com/nextauthjs/next-auth/discussions/2808#discussioncomment-6021287
+ allowDangerousEmailAccountLinking: true,
+ }),
Github({
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
+ allowDangerousEmailAccountLinking: true,
}),
],
callbacks: {
]