Skip to content

Commit 662d52a

Browse files
local Auth
1 parent 46df667 commit 662d52a

File tree

13 files changed

+21
-182
lines changed

13 files changed

+21
-182
lines changed

src/app.module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ConfigModule } from '@nestjs/config';
1010
import { ProjectService } from './services/project/project.service';
1111
import { LanguageService } from './services/language/language.service';
1212
import { AuthModule } from './modules/auth/auth.module';
13-
import { AuthController } from './controllers/auth/auth.controller';
1413
import { UsersModule } from './modules/users/users.module';
1514

1615

@@ -27,7 +26,7 @@ import config from './config';
2726
AuthModule,
2827
UsersModule,
2928
],
30-
controllers: [AppController, ProjectsController, LanguagesController, AuthController],
29+
controllers: [AppController, ProjectsController, LanguagesController],
3130
providers: [AppService, ProjectService, LanguageService],
3231
})
3332
export class AppModule { }

src/auth/auth.module.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/controllers/users/users.controller.spec.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/controllers/users/users.controller.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/modules/auth/auth.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { LocalStrategy } from './strategies/local.strategy'
33
import { PassportModule } from '@nestjs/passport'
44
import { UsersModule } from './../users/users.module';
55
import { AuthService } from './services/auth/auth.service';
6+
import { AuthController } from './controllers/auth/auth.controller';
67
//import {UserModule}
78
@Module({
89
imports: [UsersModule, PassportModule],
910
providers: [AuthService, LocalStrategy],
11+
controllers: [AuthController]
1012
})
1113
export class AuthModule { }

src/controllers/auth/auth.controller.ts renamed to src/modules/auth/controllers/auth/auth.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class AuthController {
77
@UseGuards(AuthGuard('local'))
88
@Post('login')
99
login(@Req() req: Request) {
10+
1011
return req.user;
1112
}
1213
}

src/modules/auth/services/auth/auth.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export class AuthService {
1212
return null
1313
}
1414
const match = await bcrypt.compare(password, user.password)
15-
if (user) {
16-
return user
15+
if (user && match) {
16+
const { password, ...res} = user
17+
return res
1718
}
1819
return null
1920
}

src/modules/auth/strategies/local.strategy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { Strategy } from 'passport-local';
77
@Injectable()
88
export class LocalStrategy extends PassportStrategy(Strategy, 'local') {
99
constructor(private authService: AuthService) {
10-
super();
10+
super({
11+
usernameField: 'email',
12+
passwordField: 'password',
13+
});
1114
}
1215

1316
async validate(email: string, password: string) {

src/modules/users/controllers/users/users.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ export class UsersController {
2222
async get(@Param("id", ParseIntPipe) id: number): Promise<object> {
2323
return { data: await this.languageService.get(id) }
2424
}*/
25-
/*
25+
/**/
2626
@Get()
2727
@HttpCode(HttpStatus.FOUND)
2828
async list(@Query() params: any): Promise<object> {
29-
return { data: await this.languageService.list(params) }
30-
}
29+
return { data: await this.usersService.list(params) }
30+
}/*
3131
3232
@Put(":id")
3333
@HttpCode(HttpStatus.ACCEPTED)
3434
async update(@Param("id", ParseIntPipe) id: number, @Body(new JoiValidationPipe(createUserSchema)) payload: any): Promise<object> {
35-
return { msg: "updated", data: await this.languageService.update(id, payload) }
35+
return { msg: "updated", data: await this.usersService.update(id, payload) }
3636
}
3737
3838
@Delete(":id")
3939
@HttpCode(HttpStatus.OK)
4040
async delete(@Param("id", ParseIntPipe) id: number): Promise<object> {
41-
let deleted = await this.languageService.delete(id)
41+
let deleted = await this.usersService.delete(id)
4242
return { msg: "deleted" }
4343
}
4444
*/

src/modules/users/services/users/users.service.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,16 @@ export class UsersService {
4242
}
4343
return user
4444
}
45-
/*
46-
45+
/**/
4746
async list(params): Promise<object> {
48-
const users = await this.userRepo.find();
47+
const users = await this.userRepo.find({
48+
select: ["username", "email", "role", "creationDate"]
49+
});
4950
if (!users) {
5051
throw new NotFoundException(`no ${this.plural} found`);
5152
}
52-
return {
53-
username: user.username,
54-
email: user.email,
55-
role: user.role,
56-
projects: user.projects,
57-
creationDate: user.creationDate,
58-
}
5953
return users;
60-
}
54+
}/*
6155
async update(id: number, payload: object): Promise<object> {
6256
const element = await this.userRepo.findOne(id);
6357
if (!element) {

src/services/user/user.service.spec.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/services/user/user.service.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)