Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pnpm 9+, patch @auth/typeorm-adapter not passing roles #4

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: pnpm 9+, patch @auth/typeorm-adapter not passing roles
mkleszcz committed Aug 28, 2024
commit ef97a72f5fccf027c62fbb39abc5fa5014b64673
2 changes: 1 addition & 1 deletion .github/workflows/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions apps/app/package.json
Original file line number Diff line number Diff line change
@@ -15,10 +15,12 @@
"db:migrate": "cd ../../packages/graphql-api && pnpm run db:migrate"
},
"dependencies": {
"@alp/api-client": "*",
"@alp/core": "*",
"@alp/api-client": "workspace:*",
"@alp/core": "workspace:*",
"@alp/emails": "workspace:*",
"@alp/graphql-api": "workspace:*",
"@as-integrations/next": "^3.0.0",
"@auth/typeorm-adapter": "^1.6.0",
"@auth/typeorm-adapter": "1.6.0",
"@emotion/css": "^11.11.2",
"@emotion/server": "^11.11.0",
"@formatjs/intl-localematcher": "^0.4.2",
12 changes: 9 additions & 3 deletions apps/app/src/config/auth.ts
Original file line number Diff line number Diff line change
@@ -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'] ?? '',
@@ -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;
},
1 change: 1 addition & 0 deletions apps/app/src/types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ declare module 'next-auth' {
interface Session {
user: {
role: UserRole;
id: string;
} & DefaultSession['user'];
}

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
@@ -89,6 +89,9 @@
"pnpm": {
"overrides": {
"superjson": "1.13.1"
},
"patchedDependencies": {
"@auth/typeorm-adapter@1.6.0": "patches/@auth__typeorm-adapter@1.6.0.patch"
}
}
}
12 changes: 12 additions & 0 deletions patches/@auth__typeorm-adapter@1.6.0.patch
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,
30,859 changes: 16,368 additions & 14,491 deletions pnpm-lock.yaml

Large diffs are not rendered by default.