Connect, collaborate, and grow with a community of TypeScript developers
fix(auth): remove patch of `@auth/core` (#1376)
Julius Marmingeeeb7599f66bd
diff --git a/apps/auth-proxy/package.json b/apps/auth-proxy/package.jsonindex c9276092..584a887b 100644--- a/apps/auth-proxy/package.json+++ b/apps/auth-proxy/package.json@@ -13,7 +13,7 @@"typecheck": "tsc --noEmit"},"dependencies": {- "@auth/core": "0.0.0-manual.e9863699"+ "@auth/core": "^0.19.0"},"devDependencies": {"@repo/lint": "workspace:*",diff --git a/apps/auth-proxy/routes/[...auth].ts b/apps/auth-proxy/routes/[...auth].tsindex a5d51acb..01c4ec98 100644--- a/apps/auth-proxy/routes/[...auth].ts+++ b/apps/auth-proxy/routes/[...auth].ts@@ -11,6 +11,12 @@ export default eventHandler((event) =>Github({clientId: process.env.GITHUB_ID,clientSecret: process.env.GITHUB_SECRET,+ profile: (p) => ({+ id: p.id.toString(),+ name: p.login,+ email: p.email,+ image: p.avatar_url,+ }),}),],}),diff --git a/package.json b/package.jsonindex 348cde5b..2f8a5dab 100644--- a/package.json+++ b/package.json@@ -52,8 +52,7 @@"patchedDependencies": {"@monaco-editor/[email protected]": "patches/@[email protected]","[email protected]": "patches/[email protected]",- "@vercel/[email protected]": "patches/@[email protected]",- "@auth/[email protected]": "patches/@[email protected]"+ "@vercel/[email protected]": "patches/@[email protected]"}}}diff --git a/packages/auth/package.json b/packages/auth/package.jsonindex e5a020c9..8d09a7bc 100644--- a/packages/auth/package.json+++ b/packages/auth/package.json@@ -28,9 +28,9 @@"typecheck": "tsc --noEmit"},"dependencies": {- "@auth/prisma-adapter": "^1.0.10",+ "@auth/prisma-adapter": "^1.0.12","@repo/db": "workspace:*",- "next-auth": "5.0.0-beta.3"+ "next-auth": "5.0.0-beta.4"},"devDependencies": {"@repo/lint": "workspace:*",diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.tsindex 50f1b4f0..510cf686 100644--- a/packages/auth/src/server.ts+++ b/packages/auth/src/server.ts@@ -1,7 +1,7 @@import { PrismaAdapter } from '@auth/prisma-adapter';import type { Role, RoleTypes } from '@repo/db/types';-import type { Adapter } from '@auth/core/adapters';-import { type DefaultSession } from 'next-auth';+import type { Adapter, AdapterUser, AdapterSession } from '@auth/core/adapters';+import { type DefaultSession, type User } from 'next-auth';import GitHubProvider from 'next-auth/providers/github';import { prisma } from '@repo/db';import NextAuth from './next-auth';@@ -15,8 +15,8 @@ export type { Session, DefaultSession as DefaultAuthSession } from 'next-auth';* @see https://next-auth.js.org/getting-started/typescript#module-augmentation*/declare module 'next-auth' {- interface Session extends DefaultSession {- user?: DefaultSession['user'] & {+ interface Session {+ user: DefaultSession['user'] & {id: string;role: RoleTypes[];};@@ -59,57 +59,57 @@ export const {},},},- callbacks: {- session: async ({ session, user }) => {- let userRoles: RoleTypes[] = [];- if (user.roles) {- userRoles = user.roles.reduce((acc: RoleTypes[], role) => {- acc.push(role.role);- return acc;- }, []);- }- if (!userRoles.includes('USER')) {- const updatedUser = await prisma.user.update({- where: {- id: user.id,- },- data: {- roles: {- connectOrCreate: {- where: {- role: 'USER',- },- create: {- role: 'USER',- },- },+ adapter: {+ ...(PrismaAdapter(prisma) as Adapter),+ // Override createUser method to add default USER role+ createUser: (data) =>+ prisma.user.create({+ data: {+ ...data,+ name: data.name ?? '',+ roles: {+ connectOrCreate: {+ where: { role: 'USER' },+ create: { role: 'USER' },},},- include: {- roles: true,- },- });- userRoles = updatedUser.roles.reduce((acc: RoleTypes[], role) => {- acc.push(role.role);- return acc;- }, []);- }+ },+ include: { roles: true },+ }) as Promise<AdapterUser>,+ // Override getSessionAndUser method to include roles. Avoids a second db query in session callback+ getSessionAndUser: async (sessionToken) => {+ const userAndSession = await prisma.session.findUnique({+ where: { sessionToken },+ include: { user: { include: { roles: true } } },+ });+ if (!userAndSession) return null;+ const { user, ...session } = userAndSession;+ return { user, session } as { session: AdapterSession; user: AdapterUser };+ },+ },+ callbacks: {+ session: async ({ session, user }) => {return {...session,user: {...session.user,id: user.id,- role: userRoles,- createAt: user.createdAt,+ role: user.roles.map((r) => r.role),},};},},- adapter: PrismaAdapter(prisma) as Adapter,providers: [GitHubProvider({clientId: process.env.GITHUB_ID!,clientSecret: process.env.GITHUB_SECRET!,+ profile: (p) =>+ ({+ id: p.id.toString(),+ name: p.login,+ email: p.email,+ image: p.avatar_url,+ }) as User, // TODO: Remove typecast}),],});diff --git a/patches/@[email protected] b/patches/@[email protected]deleted file mode 100644index 030b3f87..00000000--- a/patches/@[email protected]+++ /dev/null@@ -1,114 +0,0 @@-diff --git a/providers/github.js b/providers/github.js-index 4b28537419b55d799bbda68cea5936d8033520ef..aa511c6ee018e37a5ed880160da53447c197c5ab 100644---- a/providers/github.js-+++ b/providers/github.js-@@ -60,57 +60,57 @@- * :::- */- export default function GitHub(config) {-- return {-- id: "github",-- name: "GitHub",-- type: "oauth",-- authorization: {-- url: "https://github.com/login/oauth/authorize",-- params: { scope: "read:user user:email" },-- },-- token: "https://github.com/login/oauth/access_token",-- userinfo: {-- url: "https://api.github.com/user",-- async request({ tokens, provider }) {-- const profile = await fetch(provider.userinfo?.url, {-- headers: {-- Authorization: `Bearer ${tokens.access_token}`,-- "User-Agent": "authjs",-- },-- }).then(async (res) => await res.json());-- if (!profile.email) {-- // If the user does not have a public email, get another via the GitHub API-- // See https://docs.github.com/en/rest/users/emails#list-public-email-addresses-for-the-authenticated-user-- const res = await fetch("https://api.github.com/user/emails", {-- headers: {-- Authorization: `Bearer ${tokens.access_token}`,-- "User-Agent": "authjs",-- },-- });-- if (res.ok) {-- const emails = await res.json();-- profile.email = (emails.find((e) => e.primary) ?? emails[0]).email;-- }-- }-- return profile;-+ return {-+ id: "github",-+ name: "GitHub",-+ type: "oauth",-+ authorization: {-+ url: "https://github.com/login/oauth/authorize",-+ params: { scope: "read:user user:email" },-+ },-+ token: "https://github.com/login/oauth/access_token",-+ userinfo: {-+ url: "https://api.github.com/user",-+ async request({ tokens, provider }) {-+ const profile = await fetch(provider.userinfo?.url, {-+ headers: {-+ Authorization: `Bearer ${tokens.access_token}`,-+ "User-Agent": "authjs",-+ },-+ }).then(async (res) => await res.json());-+ if (!profile.email) {-+ // If the user does not have a public email, get another via the GitHub API-+ // See https://docs.github.com/en/rest/users/emails#list-public-email-addresses-for-the-authenticated-user-+ const res = await fetch("https://api.github.com/user/emails", {-+ headers: {-+ Authorization: `Bearer ${tokens.access_token}`,-+ "User-Agent": "authjs",- },-- },-- profile(profile) {-- return {-- id: profile.id.toString(),-- name: profile.name ?? profile.login,-- email: profile.email,-- image: profile.avatar_url,-- };-- },-- style: {-- logo: "/github.svg",-- logoDark: "/github-dark.svg",-- bg: "#fff",-- bgDark: "#24292f",-- text: "#000",-- textDark: "#fff",-- },-- options: config,-- };-+ });-+ if (res.ok) {-+ const emails = await res.json();-+ profile.email = (emails.find((e) => e.primary) ?? emails[0]).email;-+ }-+ }-+ return profile;-+ },-+ },-+ profile(profile) {-+ return {-+ id: profile.id.toString(),-+ name: profile.login,-+ email: profile.email,-+ image: profile.avatar_url,-+ };-+ },-+ style: {-+ logo: "/github.svg",-+ logoDark: "/github-dark.svg",-+ bg: "#fff",-+ bgDark: "#24292f",-+ text: "#000",-+ textDark: "#fff",-+ },-+ options: config,-+ };- }\ No newline at end of filediff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 9d4cf786..2c71ac95 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -5,9 +5,6 @@ settings:excludeLinksFromLockfile: falsepatchedDependencies:- '@auth/[email protected]':- hash: ryv2agbjdbjrmhkqum2c27cxhe- path: patches/@[email protected]'@monaco-editor/[email protected]':hash: xep4qb27qzc6gvlhv2fxe3r2kapath: patches/@[email protected]@@ -183,8 +180,8 @@ importers:apps/auth-proxy:dependencies:'@auth/core':- specifier: 0.0.0-manual.e9863699- version: 0.0.0-manual.e9863699(patch_hash=ryv2agbjdbjrmhkqum2c27cxhe)+ specifier: ^0.19.0+ version: 0.19.0devDependencies:'@repo/lint':specifier: workspace:*@@ -492,14 +489,14 @@ importers:packages/auth:dependencies:'@auth/prisma-adapter':- specifier: ^1.0.10- version: 1.0.10(@prisma/[email protected])+ specifier: ^1.0.12+ version: 1.0.12(@prisma/[email protected])'@repo/db':specifier: workspace:*version: link:../dbnext-auth:- specifier: 5.0.0-beta.3- version: 5.0.0-beta.3([email protected])([email protected])+ specifier: 5.0.0-beta.4+ version: 5.0.0-beta.4([email protected])([email protected])devDependencies:'@repo/lint':specifier: workspace:*@@ -964,8 +961,8 @@ packages:'@jridgewell/trace-mapping': 0.3.18dev: false- /@auth/[email protected](patch_hash=ryv2agbjdbjrmhkqum2c27cxhe):- resolution: {integrity: sha512-/hVzGuFw7nAZimliD8kpuKnNjvkRu+jpaVhYB/FaIXLNJFNwhbO2MgXBnr5tvLIHgRJnR5C9UN5RNpQXiFHuSA==}+ /@auth/[email protected]:+ resolution: {integrity: sha512-GsNhsP1xE/3FoNS3dVkPjqRljLNJ4iyL2OLv3klQGNvw3bMpROFcK4lqhx7+pPHiamnVaYt2vg1xbB+lsNaevg==}peerDependencies:nodemailer: ^6.8.0peerDependenciesMeta:@@ -973,16 +970,15 @@ packages:optional: truedependencies:'@panva/hkdf': 1.1.1- cookie: 0.5.0- jose: 4.15.4+ cookie: 0.6.0+ jose: 5.1.3oauth4webapi: 2.4.0preact: 10.11.3preact-render-to-string: 5.2.3([email protected])dev: false- patched: true- /@auth/[email protected]:- resolution: {integrity: sha512-Ql8YobXp57mbXqHNaaroIAgBopKaxWI+3Tlu1rGcXW5KPzXdfTqijZ4HOuZvWKqmhbMWQ9xS9r8uG4fMonZYwg==}+ /@auth/[email protected]:+ resolution: {integrity: sha512-BkFg2SoNftMN6A2Sn2g1lLFLTO74qMtFKsZmSCEF9d1csqSaEXIv50k6OrfniODWi5tZP8bcfSxGodv75khlOA==}peerDependencies:nodemailer: ^6.8.0peerDependenciesMeta:@@ -998,12 +994,12 @@ packages:preact-render-to-string: 5.2.3([email protected])dev: false- /@auth/[email protected](@prisma/[email protected]):- resolution: {integrity: sha512-k2rrlgVwhyZlLtxm27FWeY7spsznIxAjdTgYuXFtF5jLEG6v1Ju1Y3cgVld8BKNljhmVaSJ8xVmaK/U+roD1DA==}+ /@auth/[email protected](@prisma/[email protected]):+ resolution: {integrity: sha512-vLsbIgvpJUVpQLCDvSG16bg/uisf6y2TYHzgR1zriwMu3WdrhuG2RxrypNHNdhJZoGW0mL57QEvGVh+C9AtsRA==}peerDependencies:'@prisma/client': '>=2.26.0 || >=3 || >=4 || >=5'dependencies:- '@auth/core': 0.18.5+ '@auth/core': 0.19.0'@prisma/client': 5.7.0([email protected])transitivePeerDependencies:- nodemailer@@ -2503,7 +2499,7 @@ packages:eslint: ^6.0.0 || ^7.0.0 || >=8.0.0dependencies:eslint: 8.56.0- eslint-visitor-keys: 3.4.3+ eslint-visitor-keys: 3.4.1dev: true/@eslint-community/[email protected]:@@ -3388,6 +3384,7 @@ packages:dependencies:is-glob: 4.0.3micromatch: 4.0.5+ napi-wasm: 1.1.0dev: truebundledDependencies:- napi-wasm@@ -10207,10 +10204,6 @@ packages:resolution: {integrity: sha512-j8GhLiKmUAh+dsFXlX1aJCbt5KMibuKb+d7j1JaOJG6s2UjX1PQlW+OKB/sD4a/5ZYF4RcmYmLSndOoU3Lt/3g==}dev: false- resolution: {integrity: sha512-W+oqK4H+r5sITxfxpSU+MMdr/YSWGvgZMQDIsNoBDGGy4i7GBPTtvFKibQzW06n3U3TqHjhvBJsirShsEJ6eeQ==}- dev: false-resolution: {integrity: sha512-GPExOkcMsCLBTi1YetY2LmkoY559fss0+0KVa6kOfb2YFe84nAM7Nm/XzuZozah4iHgmBGrCOHL5/cy670SBRw==}dev: false@@ -11262,6 +11255,10 @@ packages:engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}hasBin: true+ resolution: {integrity: sha512-lHwIAJbmLSjF9VDRm9GoVOy9AGp3aIvkjv+Kvz9h16QR3uSVYH78PNQUnT2U4X53mhlnV2M7wrhibQ3GHicDmg==}+ dev: true+resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==}@@ -11301,8 +11298,8 @@ packages:uuid: 8.3.2dev: false- resolution: {integrity: sha512-WOKhATBFGeONV+29HzFmspNmL7NXxrsCWLfaDKmAd/4DD1nqXE0BzNFH8t3SJBx7PUDMnB6F7xB76LM/AaV1MQ==}+ resolution: {integrity: sha512-vgocjvwPA8gxd/zrIP/vr9lJ/HeNe+C56lPP1D3sdyenHt8KncQV6ro7q0xCsDp1fcOKx7WAWVZH5o8aMxDzgw==}peerDependencies:next: ^14nodemailer: ^6.6.5@@ -11311,7 +11308,7 @@ packages:nodemailer:optional: truedependencies:- '@auth/core': 0.0.0-manual.e9863699(patch_hash=ryv2agbjdbjrmhkqum2c27cxhe)+ '@auth/core': 0.18.4react: 18.2.0dev: false