about authentication in nestjs #158
-
Following the Nestjs documentation you can see that the user service is injected, but in this case what should the approach be? Inject the userRepo? use the QueryBus of find-users? create a service in the user module just to satisfy the authentication service? import { Injectable, UnauthorizedException } from '@nestjs/common';
import { UsersService } from '../users/users.service';
@Injectable()
export class AuthService {
constructor(private usersService: UsersService) {}
async signIn(username: string, pass: string): Promise<any> {
const user = await this.usersService.findOne(username);
if (user?.password !== pass) {
throw new UnauthorizedException();
}
const { password, ...result } = user;
// TODO: Generate a JWT and return it here
// instead of the user object
return result;
}
} Thanks in advance |
Beta Was this translation helpful? Give feedback.
Answered by
Sairyss
Mar 8, 2024
Replies: 1 comment
-
If you have a query for findUsers, use that. Otherwise injecting userRepo is an option too. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
betelgense
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have a query for findUsers, use that. Otherwise injecting userRepo is an option too.