Skip to content

Commit

Permalink
[backend] hash password on user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
usatie committed Nov 4, 2023
1 parent 3fa414d commit ae6033c
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.0.0",
"@prisma/client": "5.5.0",
"bcrypt": "^5.1.1",
"pg-promise": "^11.5.4",
"prisma": "^5.5.0",
"reflect-metadata": "^0.1.13",
Expand Down
4 changes: 4 additions & 0 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { Injectable } from '@nestjs/common';
import { UpdateUserDto } from './dto/update-user.dto';
import { PrismaService } from 'src/prisma.service';
import { User, Prisma } from '@prisma/client';
import bcrypt from 'bcrypt';

@Injectable()
export class UserService {
constructor(private prisma: PrismaService) {}

async create(data: Prisma.UserCreateInput): Promise<User> {
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(data.password, saltRounds);
data.password = hashedPassword;
return this.prisma.user.create({ data });
}

Expand Down
Loading

0 comments on commit ae6033c

Please sign in to comment.