mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 17:08:34 +00:00
fix: changed organization id to slug
This commit is contained in:
parent
d2bc9dd1e5
commit
0a4346dcaa
2 changed files with 20 additions and 3 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { ExecutionContext, Injectable, NotFoundException, UnauthorizedException } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { UsersService } from '@services/users.service';
|
||||
import { AppsService } from 'src/services/apps.service';
|
||||
|
||||
@Injectable()
|
||||
export class AppAuthGuard extends AuthGuard('jwt') {
|
||||
constructor(private appsService: AppsService) {
|
||||
constructor(private appsService: AppsService, private usersService: UsersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
|
@ -30,9 +31,15 @@ export class AppAuthGuard extends AuthGuard('jwt') {
|
|||
const authResult = await super.canActivate(context);
|
||||
return authResult;
|
||||
} catch (error) {
|
||||
let organizationSlug: string;
|
||||
if (app?.organizationId) {
|
||||
const organization = await this.usersService.getAppOrganizationDetails(app);
|
||||
organizationSlug = organization.slug || organization.id;
|
||||
}
|
||||
|
||||
throw new UnauthorizedException(
|
||||
JSON.stringify({
|
||||
organizationId: app?.organizationId,
|
||||
organizationId: organizationSlug,
|
||||
message: 'Authentication is required to access this app.',
|
||||
})
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { BadRequestException } from '@nestjs/common';
|
|||
import { cleanObject, dbTransactionWrap } from 'src/helpers/utils.helper';
|
||||
import { CreateFileDto } from '@dto/create-file.dto';
|
||||
import { WORKSPACE_USER_STATUS } from 'src/helpers/user_lifecycle';
|
||||
import { Organization } from 'src/entities/organization.entity';
|
||||
const uuid = require('uuid');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
|
|
@ -21,13 +22,22 @@ export class UsersService {
|
|||
@InjectRepository(User)
|
||||
private usersRepository: Repository<User>,
|
||||
@InjectRepository(App)
|
||||
private appsRepository: Repository<App>
|
||||
private appsRepository: Repository<App>,
|
||||
@InjectRepository(Organization)
|
||||
private organizationsRepository: Repository<Organization>
|
||||
) {}
|
||||
|
||||
async getCount(): Promise<number> {
|
||||
return this.usersRepository.count();
|
||||
}
|
||||
|
||||
async getAppOrganizationDetails(app: App): Promise<Organization> {
|
||||
return this.organizationsRepository.findOneOrFail({
|
||||
select: ['id', 'slug'],
|
||||
where: { id: app.organizationId },
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(where = {}): Promise<User> {
|
||||
return this.usersRepository.findOne({ where });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue