From 3c12fff8592711a902fa8e8fae1fc5b40e387db8 Mon Sep 17 00:00:00 2001 From: motatoes Date: Tue, 19 Nov 2024 13:16:14 +0000 Subject: [PATCH 1/2] supporting dynamic providers --- package.json | 1 + pnpm-lock.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ src/auth.ts | 23 ++++++++++++++++++----- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2c317573..25de163f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "packageManager": "pnpm@9.0.6", "dependencies": { "@ai-sdk/openai": "^0.0.13", + "@auth/core": "^0.37.4", "@dnd-kit/core": "^6.1.0", "@headlessui/react": "^1.7.18", "@headlessui/tailwindcss": "^0.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb80f4fc..99c20df4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@ai-sdk/openai': specifier: ^0.0.13 version: 0.0.13(zod@3.23.8) + '@auth/core': + specifier: ^0.37.4 + version: 0.37.4(nodemailer@6.9.14) '@dnd-kit/core': specifier: ^6.1.0 version: 6.1.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -812,6 +815,20 @@ packages: nodemailer: optional: true + '@auth/core@0.37.4': + resolution: {integrity: sha512-HOXJwXWXQRhbBDHlMU0K/6FT1v+wjtzdKhsNg0ZN7/gne6XPsIrjZ4daMcFnbq0Z/vsAbYBinQhhua0d77v7qw==} + peerDependencies: + '@simplewebauthn/browser': ^9.0.1 + '@simplewebauthn/server': ^9.0.2 + nodemailer: ^6.8.0 + peerDependenciesMeta: + '@simplewebauthn/browser': + optional: true + '@simplewebauthn/server': + optional: true + nodemailer: + optional: true + '@babel/code-frame@7.24.7': resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==} engines: {node: '>=6.9.0'} @@ -7923,12 +7940,20 @@ packages: peerDependencies: preact: '>=10' + preact-render-to-string@6.5.11: + resolution: {integrity: sha512-ubnauqoGczeGISiOh6RjX0/cdaF8v/oDXIjO85XALCQjwQP+SB4RDXXtvZ6yTYSjG+PC1QRP2AhPgCEsM2EvUw==} + peerDependencies: + preact: '>=10' + preact@10.11.3: resolution: {integrity: sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==} preact@10.22.1: resolution: {integrity: sha512-jRYbDDgMpIb5LHq3hkI0bbl+l/TQ9UnkdQ0ww+lp+4MMOdqaUYdFc5qeyP+IV8FAd/2Em7drVPeKdQxsiWCf/A==} + preact@10.24.3: + resolution: {integrity: sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA==} + prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -9964,6 +9989,16 @@ snapshots: optionalDependencies: nodemailer: 6.9.14 + '@auth/core@0.37.4(nodemailer@6.9.14)': + dependencies: + '@panva/hkdf': 1.2.1 + jose: 5.9.6 + oauth4webapi: 3.1.1 + preact: 10.24.3 + preact-render-to-string: 6.5.11(preact@10.24.3) + optionalDependencies: + nodemailer: 6.9.14 + '@babel/code-frame@7.24.7': dependencies: '@babel/highlight': 7.24.7 @@ -18577,10 +18612,16 @@ snapshots: preact: 10.11.3 pretty-format: 3.8.0 + preact-render-to-string@6.5.11(preact@10.24.3): + dependencies: + preact: 10.24.3 + preact@10.11.3: {} preact@10.22.1: {} + preact@10.24.3: {} + prelude-ls@1.2.1: {} prettier-linter-helpers@1.0.0: diff --git a/src/auth.ts b/src/auth.ts index 5ea60ef9..56fc98aa 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,13 +1,26 @@ +import type { OAuthConfig } from '@auth/core/providers'; import NextAuth from 'next-auth'; import Auth0 from 'next-auth/providers/auth0'; +import Okta from 'next-auth/providers/okta'; + +function getAuthProviders() : OAuthConfig[] { + let providers : OAuthConfig[] = [] + if (process.env.AUTH_PROVIDER_AUTH0_ENABLED==="1") { + providers.push(Auth0({ + authorization: { params: { prompt: 'login' } }, + })) + } + if (process.env.AUTH_PROVIDER_OKTA_ENABLED==="1") { + providers.push(Okta({ + authorization: { params: { prompt: 'login' } }, + })) + } + return providers +} export const { handlers, signIn, signOut, auth } = NextAuth({ //providers: [WorkOS({ connection: 'conn_01HVH5N4RFQVD9DH5QWGYT844V' })], - providers: [ - Auth0({ - authorization: { params: { prompt: 'login' } }, - }), - ], + providers: getAuthProviders(), callbacks: { authorized: async ({ auth }) => { // Logged in users are authenticated, otherwise redirect to login page From e72984c0f373cb8767a1918d2133fc02085d8af5 Mon Sep 17 00:00:00 2001 From: motatoes Date: Tue, 19 Nov 2024 13:30:34 +0000 Subject: [PATCH 2/2] fix build --- src/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auth.ts b/src/auth.ts index 56fc98aa..d1ae8b7a 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -4,7 +4,7 @@ import Auth0 from 'next-auth/providers/auth0'; import Okta from 'next-auth/providers/okta'; function getAuthProviders() : OAuthConfig[] { - let providers : OAuthConfig[] = [] + const providers : OAuthConfig[] = [] if (process.env.AUTH_PROVIDER_AUTH0_ENABLED==="1") { providers.push(Auth0({ authorization: { params: { prompt: 'login' } },