Skip to content

Commit

Permalink
fix: pnpm 9+, patch @auth/typeorm-adapter not passing roles
Browse files Browse the repository at this point in the history
  • Loading branch information
mkleszcz committed Aug 28, 2024
1 parent 8eeca4c commit c3e1956
Show file tree
Hide file tree
Showing 7 changed files with 14,426 additions and 11,874 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
steps:
- uses: pnpm/action-setup@v2
with:
version: 8
version: 9.5.x

- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v3
Expand Down
4 changes: 2 additions & 2 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"db:migrate": "cd ../../packages/graphql-api && pnpm run db:migrate"
},
"dependencies": {
"@alp/api-client": "*",
"@alp/core": "*",
"@alp/api-client": "workspace:*",
"@alp/core": "workspace:*",
"@as-integrations/next": "^3.0.0",
"@auth/typeorm-adapter": "^1.6.0",
"@emotion/css": "^11.11.2",
Expand Down
12 changes: 9 additions & 3 deletions apps/app/src/config/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import GoogleProvider from 'next-auth/providers/google';

import { WelcomeEmail, sendEmail } from '@alp/emails';
import { dataSourceOptions } from '@alp/graphql-api/data-source';
import * as entities from '@alp/graphql-api/entity/auth';
import { AccountEntity, SessionEntity, UserEntity, VerificationTokenEntity } from '@alp/graphql-api/entity/auth';
import { UserRole } from '@alp/graphql-api/types';

export const authOptions: NextAuthOptions = {
// @ts-ignore
adapter: TypeORMAdapter(dataSourceOptions, { entities }),
adapter: TypeORMAdapter(dataSourceOptions, {
entities: { UserEntity, SessionEntity, AccountEntity, VerificationTokenEntity },
}),
providers: [
GoogleProvider({
clientId: process.env['OAUTH_GOOGLE_CLIENT_ID'] ?? '',
Expand All @@ -28,10 +30,14 @@ export const authOptions: NextAuthOptions = {
callbacks: {
jwt({ token, user }) {
// save role in JWT
if (user) token.role = user.role;
if (user) {
token.id = user.id;
token.role = user.role;
}
return token;
},
session({ session, token }) {
session.user.id = token.id as string;
session.user.role = token.role as UserRole;
return session;
},
Expand Down
1 change: 1 addition & 0 deletions apps/app/src/types/next-auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module 'next-auth' {
interface Session {
user: {
role: UserRole;
id: string;
} & DefaultSession['user'];
}

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@alp/internal-core": "*",
"@alp/internal-core": "workspace:*",
"@faker-js/faker": "^8.0.2",
"@nx/devkit": "^16.9.1",
"@nx/eslint-plugin": "^16.9.1",
Expand Down Expand Up @@ -89,6 +89,9 @@
"pnpm": {
"overrides": {
"superjson": "1.13.1"
},
"patchedDependencies": {
"@auth/[email protected]": "patches/@[email protected]"
}
}
}
12 changes: 12 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/index.js b/index.js
index f8d34785aa2c60c874ab0fa64766ba533d52befe..ffe861208b47c4ee5dc33ed37964d859e3b6dcfe 100644
--- a/index.js
+++ b/index.js
@@ -243,6 +243,7 @@ export function TypeORMAdapter(dataSource, options) {
const c = {
dataSource,
entities: {
+ ...dataSource.entities,
UserEntity: entities?.UserEntity ?? defaultEntities.UserEntity,
SessionEntity: entities?.SessionEntity ?? defaultEntities.SessionEntity,
AccountEntity: entities?.AccountEntity ?? defaultEntities.AccountEntity,
26,264 changes: 14,397 additions & 11,867 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

0 comments on commit c3e1956

Please sign in to comment.