mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:34:54 +00:00
add client relation btw user and client
This commit is contained in:
@ -37,8 +37,12 @@ export class UserAuthController {
|
||||
summary: ControllerRoute.AUTHENTICATION.ACTIONS.SIGN_UP_SUMMARY,
|
||||
description: ControllerRoute.AUTHENTICATION.ACTIONS.SIGN_UP_DESCRIPTION,
|
||||
})
|
||||
async signUp(@Body() userSignUpDto: UserSignUpDto) {
|
||||
const signupUser = await this.userAuthService.signUp(userSignUpDto);
|
||||
async signUp(@Body() userSignUpDto: UserSignUpDto, @Req() req: any) {
|
||||
const clientUuid = req.client.uuid;
|
||||
const signupUser = await this.userAuthService.signUp(
|
||||
userSignUpDto,
|
||||
clientUuid,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: {
|
||||
|
||||
@ -34,7 +34,10 @@ export class UserAuthService {
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async signUp(userSignUpDto: UserSignUpDto): Promise<UserEntity> {
|
||||
async signUp(
|
||||
userSignUpDto: UserSignUpDto,
|
||||
clientUuid?: string,
|
||||
): Promise<UserEntity> {
|
||||
const findUser = await this.findUser(userSignUpDto.email);
|
||||
|
||||
if (findUser) {
|
||||
@ -63,6 +66,7 @@ export class UserAuthService {
|
||||
hasAcceptedAppAgreement,
|
||||
password: hashedPassword,
|
||||
roleType: { uuid: spaceMemberRole.uuid },
|
||||
client: { uuid: clientUuid },
|
||||
region: regionUuid
|
||||
? {
|
||||
uuid: regionUuid,
|
||||
|
||||
@ -20,6 +20,8 @@ export class ClientGuard extends AuthGuard('jwt') {
|
||||
if (!this.validateToken(decoded)) {
|
||||
throw new UnauthorizedException('Invalid token');
|
||||
}
|
||||
|
||||
request.client = (decoded as jwt.JwtPayload).client;
|
||||
} catch (err) {
|
||||
throw new UnauthorizedException('Invalid token');
|
||||
}
|
||||
@ -36,14 +38,6 @@ export class ClientGuard extends AuthGuard('jwt') {
|
||||
}
|
||||
|
||||
private validateToken(decoded: any): boolean {
|
||||
if (
|
||||
decoded &&
|
||||
decoded.client &&
|
||||
decoded.client.clientId &&
|
||||
decoded.client.uuid
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return decoded?.client?.clientId && decoded?.client?.uuid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user