Skip to content

Commit

Permalink
Merge pull request #92 from zhumeisongsong/feature/register-JwtModule…
Browse files Browse the repository at this point in the history
…-as-global

feat: ✨ register JwtModule as global
  • Loading branch information
zhumeisongsong authored Dec 3, 2024
2 parents e10be29 + 28194fd commit dbe0312
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libs/auth/application/src/lib/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UsersService } from '@users/application';
import { JwtService } from '@nestjs/jwt';
import { AwsCognitoService } from '@shared/infrastructure-aws-cognito';

// Implement the authentication logic
export class AuthService {
constructor(
private awsCognitoService: AwsCognitoService,
Expand All @@ -11,6 +12,7 @@ export class AuthService {
private readonly logger = new Logger(AuthService.name),
) {}

// Retrieving a user and verifying the password
async signIn(
email: string,
pass: string,
Expand Down
19 changes: 18 additions & 1 deletion libs/auth/interface-adapters/src/lib/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { AuthService } from '@auth/application';
import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { UsersModule } from '@users/interface-adapters';

import { AuthResolver } from './resolver/auth.resolver';

@Module({
imports: [
UsersModule,
JwtModule.registerAsync({
global: true,
useFactory: (configService: ConfigService) => {
const jwtConfig = configService.get('jwt');
return {
secret: jwtConfig.secret,
signOptions: { expiresIn: '60s' },
};
},
inject: [ConfigService],
}),
],
providers: [AuthResolver, AuthService],
exports: [],
exports: [AuthService],
})
export class AuthModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Resolver, Mutation, Args } from '@nestjs/graphql';

import { SignInInputDto } from '../dto/sign-in-input.dto';

// Expose the authentication endpoints
@Resolver()
export class AuthResolver {
constructor(private authService: AuthService) {}
Expand Down

0 comments on commit dbe0312

Please sign in to comment.