Various fixes: profilePicture / logo upload, imageIdentifiers (#6530)

In this PR:
- refactoring auth module to extract a jwt module that can be re-used
from other part of the app (avoiding circular dependencies file module
=> auth => file (file and auth both need jwt actually)
- activating imageIdentfier on person on workspace creation (this will
put back the images on people)
- fixing picture upload (we were missing some fileToken)
This commit is contained in:
Charles Bochet
2024-08-04 15:08:25 +02:00
committed by GitHub
parent e787215e15
commit c543716381
15 changed files with 143 additions and 91 deletions

View File

@ -0,0 +1,27 @@
/* eslint-disable no-restricted-imports */
import { Module } from '@nestjs/common';
import { JwtModule as NestJwtModule } from '@nestjs/jwt';
import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';
import { EnvironmentModule } from 'src/engine/integrations/environment/environment.module';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
const InternalJwtModule = NestJwtModule.registerAsync({
useFactory: async (environmentService: EnvironmentService) => {
return {
secret: environmentService.get('ACCESS_TOKEN_SECRET'),
signOptions: {
expiresIn: environmentService.get('ACCESS_TOKEN_EXPIRES_IN'),
},
};
},
inject: [EnvironmentService],
});
@Module({
imports: [InternalJwtModule, EnvironmentModule],
controllers: [],
providers: [JwtWrapperService],
exports: [JwtWrapperService],
})
export class JwtModule {}

View File

@ -0,0 +1,21 @@
import { Injectable } from '@nestjs/common';
import { JwtService, JwtSignOptions, JwtVerifyOptions } from '@nestjs/jwt';
import * as jwt from 'jsonwebtoken';
@Injectable()
export class JwtWrapperService {
constructor(private readonly jwtService: JwtService) {}
sign(payload: string, options?: JwtSignOptions): string {
return this.jwtService.sign(payload, options);
}
verify<T extends object = any>(token: string, options?: JwtVerifyOptions): T {
return this.jwtService.verify(token, options);
}
decode<T = any>(payload: string, options: jwt.DecodeOptions): T {
return this.jwtService.decode(payload, options);
}
}