/
sigma
/
Acloud-server
Обзор
Документация
Войти
/
sigma
/
Acloud-server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/auth/auth.service.ts
40 строк
1 KB
Александр Пимкин
first_commit
17 апр 2025, 11:44
17 апр 2025, 11:44
293b9b4
Код
Авторство
О чём код?
import { ForbiddenException, Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { CreateUserDto } from 'src/users/dto/create-user.dto'; import { UserEntity } from 'src/users/entities/user.entity'; import { UsersService } from 'src/users/users.service'; @Injectable() export class AuthService { constructor( private usersService: UsersService, private jwtService: JwtService, ) {} async validateUser(email: string, password: string): Promise<any> { const user = await this.usersService.findByEmail(email); if (user && user.password === password) { const { password, ...result } = user; return result; } return null; } async register(dto: CreateUserDto) { try { const userData = await this.usersService.create(dto); return { token: this.jwtService.sign({ id: userData.id }), }; } catch (e) { console.log(e); throw new ForbiddenException('Ошибка при регистрации'); } } async login(user: UserEntity) { return { token: this.jwtService.sign({ id: user.id }), }; } }