Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

some fixes & improvements

Blue Mouse4ee4d39d3b63
diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts
index 585e8b633..65b2182da 100644
--- a/src/auth/auth.controller.ts
+++ b/src/auth/auth.controller.ts
@@ -104,6 +104,7 @@ export class AuthController {
return {
accessToken: jwtTokens.accessToken,
refreshToken: jwtTokens.refreshToken,
+ user: this.userService.omitSensitiveData(newUser),
}
}
@@ -138,12 +139,14 @@ export class AuthController {
if (user.isTwoFactorAuthenticationEnabled) {
user = _pick(user, ['isTwoFactorAuthenticationEnabled', 'email'])
+ } else {
+ user = await this.authService.getSharedProjectsForUser(user)
}
return {
accessToken: jwtTokens.accessToken,
refreshToken: jwtTokens.refreshToken,
- user,
+ user: this.userService.omitSensitiveData(user),
}
}
@@ -384,7 +387,7 @@ export class AuthController {
@CurrentUserId() userId: string,
@CurrentUser('refreshToken') refreshToken: string,
@I18n() i18n: I18nContext,
- ) {
+ ): Promise<void> {
const user = await this.userService.findUserById(userId)
if (!user) {
diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts
index 1497e2e30..d9bb6280e 100644
--- a/src/auth/auth.module.ts
+++ b/src/auth/auth.module.ts
@@ -6,6 +6,7 @@ import { MailerModule } from 'src/mailer/mailer.module'
import { UserModule } from 'src/user/user.module'
import { AuthController } from './auth.controller'
import { AuthService } from './auth.service'
+import { ProjectModule } from 'src/project/project.module'
import { JwtAccessTokenStrategy, JwtRefreshTokenStrategy } from './strategies'
@Module({
@@ -16,6 +17,7 @@ import { JwtAccessTokenStrategy, JwtRefreshTokenStrategy } from './strategies'
ActionTokensModule,
MailerModule,
ActionTokensModule,
+ ProjectModule,
],
controllers: [AuthController],
providers: [AuthService, JwtAccessTokenStrategy, JwtRefreshTokenStrategy],
diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts
index 8a95b6112..72b8013d5 100644
--- a/src/auth/auth.service.ts
+++ b/src/auth/auth.service.ts
@@ -17,6 +17,7 @@ import { MailerService } from 'src/mailer/mailer.service'
import { MAX_EMAIL_REQUESTS, User } from 'src/user/entities/user.entity'
import { TelegrafContext } from 'src/user/user.controller'
import { UserService } from 'src/user/user.service'
+import { ProjectService } from 'src/project/project.service'
import { Telegraf } from 'telegraf'
import { UAParser } from 'ua-parser-js'
@@ -29,6 +30,7 @@ export class AuthService {
private readonly configService: ConfigService,
private readonly mailerService: MailerService,
private readonly jwtService: JwtService,
+ private readonly projectService: ProjectService,
) {}
private async createSha1Hash(password: string): Promise<string> {
@@ -92,7 +94,7 @@ export class AuthService {
})
}
- public async createUnverifiedUser(email: string, password: string) {
+ public async createUnverifiedUser(email: string, password: string): Promise<User> {
const hashedPassword = await this.hashPassword(password)
const user = await this.userService.createUser({
@@ -135,6 +137,19 @@ export class AuthService {
return null
}
+ public async getSharedProjectsForUser(user: User): Promise<User> {
+ const sharedProjects = await this.projectService.findShare({
+ where: {
+ user: user.id,
+ },
+ relations: ['project'],
+ })
+
+ user.sharedProjects = sharedProjects
+
+ return user
+ }
+
private async comparePassword(
password: string,
hashedPassword: string,
diff --git a/src/auth/dtos/register.dto.ts b/src/auth/dtos/register.dto.ts
index c1669d49a..05c4d0e39 100644
--- a/src/auth/dtos/register.dto.ts
+++ b/src/auth/dtos/register.dto.ts
@@ -46,4 +46,9 @@ export class RegisterResponseDto {
description: 'Refresh token (JWT)',
})
public readonly refreshToken: string
+
+ @ApiProperty({
+ description: 'User entity',
+ })
+ user: object
}
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index 6789d8ac8..390a06854 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -86,7 +86,7 @@ export class UserController {
@UseGuards(RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async me(@CurrentUserId() user_id: string): Promise<User> {
- this.logger.log({ user_id }, 'GET /auth/me')
+ this.logger.log({ user_id }, 'GET /user/me')
let user
if (isSelfhosted) {
diff --git a/src/user/user.service.ts b/src/user/user.service.ts
index 675f02ded..19dd4e776 100644
--- a/src/user/user.service.ts
+++ b/src/user/user.service.ts
@@ -6,7 +6,7 @@ import * as _size from 'lodash/size'
import * as _omit from 'lodash/omit'
import { Pagination, PaginationOptionsInterface } from '../common/pagination'
-import { User } from './entities/user.entity'
+import { User, ACCOUNT_PLANS } from './entities/user.entity'
import { UserProfileDTO } from './dto/user.dto'
import { RefreshToken } from './entities/refresh-token.entity'