Skip to content

Commit

Permalink
fix: move jwt into it's own module
Browse files Browse the repository at this point in the history
  • Loading branch information
gregfrasco committed May 8, 2023
1 parent 40e32fa commit 84a287a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
4 changes: 3 additions & 1 deletion packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { join } from 'path';
import { ConfigModule } from '@nestjs/config';
import { InviteModule } from './invite/invite.module';
import { NotificationModule } from './notification/notification.module';
import { JwtModule } from './jwt/jwt.module';

@Module({
imports: [
Expand All @@ -26,7 +27,8 @@ import { NotificationModule } from './notification/notification.module';
}
}),
InviteModule,
NotificationModule
NotificationModule,
JwtModule
]
})
export class AppModule implements NestModule {
Expand Down
25 changes: 2 additions & 23 deletions packages/server/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@ import { AuthService } from './auth.service';
import { AuthResolver } from './auth.resolver';
import { PrismaService } from '../prisma/prisma.service';
import { UserModule } from '../user/user.module';
import { JwtModule, JwtModuleOptions } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ProjectModule } from '../project/project.module';
import { NotificationModule } from '../notification/notification.module';
import { JwtModule } from '../jwt/jwt.module';

@Module({
imports: [
UserModule,
ProjectModule,
NotificationModule,
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const options: JwtModuleOptions = {
privateKey: configService.get('PRIVATE_KEY'),
publicKey: configService.get('PUBLIC_KEY_1'),
signOptions: {
expiresIn: configService.get('JWT_EXPIRATION'),
issuer: 'https://sail.bu.edu',
algorithm: 'RS256'
}
};
return options;
},
inject: [ConfigService]
})
],
imports: [UserModule, ProjectModule, NotificationModule, JwtModule],
controllers: [LoginController, SignupController, RecoveryController, PublicKeyController],
providers: [AuthResolver, AuthService, PrismaService],
exports: [AuthService]
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/invite/invite.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { PrismaService } from '../prisma/prisma.service';
import { UserModule } from '../user/user.module';
import { NotificationModule } from '../notification/notification.module';
import { AuthModule } from '../auth/auth.module';
import { JwtModule } from '../jwt/jwt.module';

@Module({
imports: [UserModule, NotificationModule, AuthModule],
imports: [UserModule, NotificationModule, AuthModule, JwtModule],
providers: [InviteService, InviteResolver, PrismaService],
exports: [InviteService]
})
Expand Down
26 changes: 26 additions & 0 deletions packages/server/src/jwt/jwt.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule as NestJwtModule, JwtModuleOptions } from '@nestjs/jwt';

@Module({
imports: [
NestJwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const options: JwtModuleOptions = {
privateKey: configService.get('PRIVATE_KEY'),
publicKey: configService.get('PUBLIC_KEY_1'),
signOptions: {
expiresIn: configService.get('JWT_EXPIRATION'),
issuer: 'https://sail.bu.edu',
algorithm: 'RS256'
}
};
return options;
},
inject: [ConfigService]
})
],
exports: [NestJwtModule]
})
export class JwtModule {}
4 changes: 2 additions & 2 deletions packages/server/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { PrismaService } from '../prisma/prisma.service';
import { UserResolver } from './user.resolver';
import { JwtModule } from '../jwt/jwt.module';

@Module({
imports: [JwtModule.register({ secret: process.env.SECRET })],
imports: [JwtModule],
controllers: [UserController],
providers: [UserService, PrismaService, UserResolver],
exports: [UserService]
Expand Down

0 comments on commit 84a287a

Please sign in to comment.