From 2bb9bda323a1af8de8731df14b20d097a17e8b3d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 15 Apr 2024 11:54:10 +0100 Subject: [PATCH] Added microsoft sign in --- src/app/api/auth/[...nextauth]/route.ts | 11 ++ .../signin/MicrosoftSignInButton.jsx | 111 ++++++++++++++++++ src/app/page.tsx | 5 + 3 files changed, 127 insertions(+) create mode 100644 src/app/components/signin/MicrosoftSignInButton.jsx diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 06af25e..bd4ae38 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,10 +1,16 @@ import NextAuth, { NextAuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; +import AzureADProvider from "next-auth/providers/azure-ad"; import { db } from "@/app/db/db"; import { user as userTable, User } from "@/app/db/schema/users"; import { eq } from "drizzle-orm"; const { GOOGLE_CLIENT_ID = "", GOOGLE_CLIENT_SECRET = "" } = process.env; +const { + AZURE_AD_CLIENT_ID = "", + AZURE_AD_CLIENT_SECRET = "", + AZURE_AD_TENANT_ID = "", +} = process.env; type OauthProvider = "google"; @@ -26,6 +32,11 @@ export const AuthOptions: NextAuthOptions = { }, }, }), + AzureADProvider({ + clientId: AZURE_AD_CLIENT_ID, + clientSecret: AZURE_AD_CLIENT_SECRET, + tenantId: AZURE_AD_TENANT_ID, + }), ], pages: { signIn: "/", diff --git a/src/app/components/signin/MicrosoftSignInButton.jsx b/src/app/components/signin/MicrosoftSignInButton.jsx new file mode 100644 index 0000000..bb881fd --- /dev/null +++ b/src/app/components/signin/MicrosoftSignInButton.jsx @@ -0,0 +1,111 @@ +"use client"; + +import { useSearchParams } from "next/navigation"; +import { signIn } from "next-auth/react"; + +import Button from "./Button"; + +const MicrosoftSignInButton = () => { + const searchParams = useSearchParams(); + const callbackUrl = searchParams.get("callbackUrl"); + + return ( + + ); +}; + +export default MicrosoftSignInButton; diff --git a/src/app/page.tsx b/src/app/page.tsx index aa42ec1..2f8a406 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,6 +1,7 @@ import { getServerSession } from "next-auth/next"; import { AuthOptions } from "./api/auth/[...nextauth]/route"; import GoogleSignInButton from "./components/signin/GoogleSignInButton"; +import MicrosoftSignInButton from "./components/signin/MicrosoftSignInButton"; import { redirect } from "next/navigation"; import Image from "next/image"; @@ -36,6 +37,10 @@ export default async function Home() {
Start managing your portfolios
+
+ +
+