diff --git a/.env.local.example b/.env.local.example index b754b2f5..a3553810 100644 --- a/.env.local.example +++ b/.env.local.example @@ -4,6 +4,9 @@ AUTH_AUTH0_ID= AUTH_AUTH0_SECRET= AUTH_AUTH0_ISSUER= +AUTH_DESCOPE_ID= +AUTH_DESCOPE_SECRET= + AUTH_FACEBOOK_ID= AUTH_FACEBOOK_SECRET= diff --git a/auth.ts b/auth.ts index cdf64d97..c9790163 100644 --- a/auth.ts +++ b/auth.ts @@ -1,39 +1,40 @@ -import NextAuth from "next-auth" -import "next-auth/jwt" +import NextAuth from "next-auth"; +import "next-auth/jwt"; -import Apple from "next-auth/providers/apple" -import Auth0 from "next-auth/providers/auth0" -import AzureB2C from "next-auth/providers/azure-ad-b2c" -import BankIDNorway from "next-auth/providers/bankid-no" -import BoxyHQSAML from "next-auth/providers/boxyhq-saml" -import Cognito from "next-auth/providers/cognito" -import Coinbase from "next-auth/providers/coinbase" -import Discord from "next-auth/providers/discord" -import Dropbox from "next-auth/providers/dropbox" -import Facebook from "next-auth/providers/facebook" -import GitHub from "next-auth/providers/github" -import GitLab from "next-auth/providers/gitlab" -import Google from "next-auth/providers/google" -import Hubspot from "next-auth/providers/hubspot" -import Keycloak from "next-auth/providers/keycloak" -import LinkedIn from "next-auth/providers/linkedin" -import Netlify from "next-auth/providers/netlify" -import Okta from "next-auth/providers/okta" -import Passage from "next-auth/providers/passage" -import Passkey from "next-auth/providers/passkey" -import Pinterest from "next-auth/providers/pinterest" -import Reddit from "next-auth/providers/reddit" -import Slack from "next-auth/providers/slack" -import Spotify from "next-auth/providers/spotify" -import Twitch from "next-auth/providers/twitch" -import Twitter from "next-auth/providers/twitter" -import WorkOS from "next-auth/providers/workos" -import Zoom from "next-auth/providers/zoom" -import { createStorage } from "unstorage" -import memoryDriver from "unstorage/drivers/memory" -import vercelKVDriver from "unstorage/drivers/vercel-kv" -import { UnstorageAdapter } from "@auth/unstorage-adapter" -import type { NextAuthConfig } from "next-auth" +import Apple from "next-auth/providers/apple"; +import Auth0 from "next-auth/providers/auth0"; +import AzureB2C from "next-auth/providers/azure-ad-b2c"; +import BankIDNorway from "next-auth/providers/bankid-no"; +import BoxyHQSAML from "next-auth/providers/boxyhq-saml"; +import Cognito from "next-auth/providers/cognito"; +import Coinbase from "next-auth/providers/coinbase"; +import Descope from "next-auth/providers/descope"; +import Discord from "next-auth/providers/discord"; +import Dropbox from "next-auth/providers/dropbox"; +import Facebook from "next-auth/providers/facebook"; +import GitHub from "next-auth/providers/github"; +import GitLab from "next-auth/providers/gitlab"; +import Google from "next-auth/providers/google"; +import Hubspot from "next-auth/providers/hubspot"; +import Keycloak from "next-auth/providers/keycloak"; +import LinkedIn from "next-auth/providers/linkedin"; +import Netlify from "next-auth/providers/netlify"; +import Okta from "next-auth/providers/okta"; +import Passage from "next-auth/providers/passage"; +import Passkey from "next-auth/providers/passkey"; +import Pinterest from "next-auth/providers/pinterest"; +import Reddit from "next-auth/providers/reddit"; +import Slack from "next-auth/providers/slack"; +import Spotify from "next-auth/providers/spotify"; +import Twitch from "next-auth/providers/twitch"; +import Twitter from "next-auth/providers/twitter"; +import WorkOS from "next-auth/providers/workos"; +import Zoom from "next-auth/providers/zoom"; +import { createStorage } from "unstorage"; +import memoryDriver from "unstorage/drivers/memory"; +import vercelKVDriver from "unstorage/drivers/vercel-kv"; +import { UnstorageAdapter } from "@auth/unstorage-adapter"; +import type { NextAuthConfig } from "next-auth"; const storage = createStorage({ driver: process.env.VERCEL @@ -43,7 +44,7 @@ const storage = createStorage({ env: false, }) : memoryDriver(), -}) +}); const config = { theme: { logo: "https://authjs.dev/img/logo-sm.png" }, @@ -64,6 +65,11 @@ const config = { }), Cognito, Coinbase, + Descope({ + clientId: process.env.AUTH_DESCOPE_ID, + clientSecret: process.env.AUTH_DESCOPE_SECRET, + checks: ["pkce", "state"], + }), Discord, Dropbox, Facebook, @@ -99,40 +105,40 @@ const config = { basePath: "/auth", callbacks: { authorized({ request, auth }) { - const { pathname } = request.nextUrl - if (pathname === "/middleware-example") return !!auth - return true + const { pathname } = request.nextUrl; + if (pathname === "/middleware-example") return !!auth; + return true; }, jwt({ token, trigger, session, account }) { - if (trigger === "update") token.name = session.user.name + if (trigger === "update") token.name = session.user.name; if (account?.provider === "keycloak") { - return { ...token, accessToken: account.access_token } + return { ...token, accessToken: account.access_token }; } - return token + return token; }, async session({ session, token }) { if (token?.accessToken) { - session.accessToken = token.accessToken + session.accessToken = token.accessToken; } - return session + return session; }, }, experimental: { enableWebAuthn: true, }, debug: process.env.NODE_ENV !== "production" ? true : false, -} satisfies NextAuthConfig +} satisfies NextAuthConfig; -export const { handlers, auth, signIn, signOut } = NextAuth(config) +export const { handlers, auth, signIn, signOut } = NextAuth(config); declare module "next-auth" { interface Session { - accessToken?: string + accessToken?: string; } } declare module "next-auth/jwt" { interface JWT { - accessToken?: string + accessToken?: string; } }