diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index ac2402a..f10061a 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -2,7 +2,7 @@ import { ForbiddenException, Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; import { AuthLoginDto, AuthRegisterDto } from './dto'; import * as argon from 'argon2'; -import { Prisma } from '@prisma/client'; +import { Prisma, User } from '@prisma/client'; import { JwtService } from '@nestjs/jwt'; import { ConfigService } from '@nestjs/config'; @@ -47,7 +47,7 @@ export class AuthService { }, }); - return this.signToken(user.id, user.email); + return this.signToken(user); } catch (error) { if (error instanceof Prisma.PrismaClientKnownRequestError) { if (error.code === 'P2002') { @@ -69,17 +69,16 @@ export class AuthService { const pwMatches = await argon.verify(user.hash, dto.password); if (!pwMatches) throw new ForbiddenException('Credentials incorrect'); - return this.signToken(user.id, user.email); + return this.signToken(user); } - async signToken( - userId: string, - email: string, - ): Promise<{ access_token: string }> { + async signToken(user: User): Promise<{ access_token: string; user: User }> { const payload = { - sub: userId, - email: email, + sub: user.id, + email: user.email, }; + user.hash = null; + const secret = this.config.get('JWT_SECRET'); const token = await this.jwt.signAsync(payload, { expiresIn: '30d', @@ -88,6 +87,7 @@ export class AuthService { return { access_token: token, + user, }; } } diff --git a/src/utils/styles.ts b/src/utils/styles.ts new file mode 100644 index 0000000..e69de29