-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
298 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
import { JwtUser } from '@app/auth'; | ||
import { Tokens } from '@app/constants'; | ||
import { MongoDbService } from '@app/mongodb'; | ||
import { RedisClient, RedisService } from '@app/redis'; | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { Collections } from '@app/constants'; | ||
import { PortalUsersEntity } from '@app/entities'; | ||
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { Db } from 'mongodb'; | ||
import moment from 'moment'; | ||
import { Collection } from 'mongodb'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
const jwtVersion = 'v1'; | ||
|
||
@Injectable() | ||
export class AuthService { | ||
constructor( | ||
@Inject(Tokens.MONGODB) private readonly db: Db, | ||
@Inject(Tokens.REDIS) private readonly redis: RedisClient, | ||
private readonly redisService: RedisService, | ||
private readonly mongoDbService: MongoDbService, | ||
private readonly jwtService: JwtService, | ||
@Inject(Collections.PORTAL_USERS) private portalUsersCollection: Collection<PortalUsersEntity>, | ||
) {} | ||
|
||
async login(userId: string) { | ||
const payload = { sub: userId, jti: uuid() } satisfies Partial<JwtUser>; | ||
async login(passKey: string) { | ||
const user = await this.portalUsersCollection.findOne({ passKey }); | ||
if (!user) throw new UnauthorizedException(); | ||
|
||
const payload = { | ||
sub: user.userId, | ||
jti: uuid(), | ||
version: jwtVersion, | ||
roles: user.roles, | ||
} satisfies Partial<JwtUser>; | ||
|
||
return { | ||
userId: user.userId, | ||
roles: user.roles, | ||
expiresIn: moment().add(30, 'days').toDate().getTime(), | ||
accessToken: this.jwtService.sign(payload, { expiresIn: '30d' }), | ||
}; | ||
} | ||
|
||
async validateJwt(jwtUser: JwtUser) { | ||
if (jwtUser.version !== jwtVersion) throw new UnauthorizedException(); | ||
return jwtUser; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './login.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export class GuildOutput { | ||
name: string; | ||
guildId: string; | ||
clans: GuildClanOutput[]; | ||
categories: ClanCategoryOutput[]; | ||
grouped: ClanCategoryGroupOutput[]; | ||
} | ||
|
||
export class GuildClanOutput { | ||
_id: string; | ||
name: string; | ||
tag: string; | ||
order: number; | ||
} | ||
|
||
export class ClanCategoryOutput { | ||
_id: string; | ||
name: string; | ||
order: number; | ||
} | ||
|
||
export class ClanCategoryGroupOutput extends ClanCategoryOutput { | ||
clans: GuildClanOutput[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './aggregated.dto'; | ||
export * from './guild-output.dto'; | ||
export * from './reorder-clan-categories.dto'; |
29 changes: 29 additions & 0 deletions
29
apps/service-auth/src/guilds/dto/reorder-clan-categories.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ArrayMinSize, IsArray, IsInt, IsNotEmpty, ValidateNested } from 'class-validator'; | ||
|
||
export class ReorderClanCategoriesInput { | ||
@ValidateNested({ each: true }) | ||
@IsArray() | ||
@ArrayMinSize(1) | ||
categories: ReorderCategoriesInput[]; | ||
} | ||
|
||
export class ReorderCategoriesInput { | ||
@IsNotEmpty() | ||
_id: string; | ||
|
||
@IsInt() | ||
order: number; | ||
|
||
@ValidateNested({ each: true }) | ||
@IsArray() | ||
@ArrayMinSize(1) | ||
clans: ReorderClansInput[]; | ||
} | ||
|
||
export class ReorderClansInput { | ||
@IsNotEmpty() | ||
_id: string; | ||
|
||
@IsInt() | ||
order: number; | ||
} |
32 changes: 0 additions & 32 deletions
32
apps/service-auth/src/guilds/dto/update-clan-categories.dto.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { ArrayMaxSize, IsNotEmpty, IsString } from 'class-validator'; | ||
import { ArrayMaxSize, ArrayMinSize, IsString } from 'class-validator'; | ||
|
||
export class BulkLinksDto { | ||
@IsString({ each: true }) | ||
@IsNotEmpty() | ||
@ArrayMinSize(1) | ||
@ArrayMaxSize(1000) | ||
input: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './bulk-links.dto'; | ||
export * from './create-links.dto'; | ||
export * from './delete-link.dto'; |
Oops, something went wrong.