mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-08 21:50:13 +02:00
added user info in sign in and sign up return
This commit is contained in:
parent
67d33dce2e
commit
b194d084cf
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
0
src/utils/styles.ts
Normal file
0
src/utils/styles.ts
Normal file
Loading…
x
Reference in New Issue
Block a user