Algumas atualizações sobre users

This commit is contained in:
Matheus Albino Brunhara
2022-05-03 17:26:22 -05:00
parent bf5620a5fc
commit 20fa4212cb
5 changed files with 1067 additions and 1335 deletions

View File

@@ -15,7 +15,7 @@ sessionsRouter.post('/', async (request, response) => {
password,
});
return response.json({ message: 'User logged in sucessfully', token: token });
return response.json({ message: 'Usuário autenticado com sucesso!', token: token });
});
export default sessionsRouter;

View File

@@ -57,8 +57,8 @@ usersRouter.get('/:id', ensureAuthenticated, async (request, response) => {
birth_date: user.birth_date,
avatar_image: user.avatar_image,
bio: user.bio,
created_at: user.created_at,
updated_at: user.updated_at,
// created_at: user.created_at,
// updated_at: user.updated_at,
};
return response.json({ data: userWithoutPassword });

View File

@@ -17,6 +17,8 @@ interface Response {
id_user: string;
}
const failedLoginMessage = { message: 'Combinação incorreta de login e senha.', statusCode: 200 }
class AuthenticateUserService {
public async execute({ login, password }: Request): Promise<Response> {
const usersRepository = getRepository(User);
@@ -28,7 +30,7 @@ class AuthenticateUserService {
// TODO, ajeitar todos os HTTP status code
// Por que tem que deixar 200 para funcionar?
if (!user) {
throw new AppError('Incorrect login/password combination.', 200);
throw new AppError(failedLoginMessage.message, failedLoginMessage.statusCode);
}
// user.password -> senha criptografada
@@ -37,7 +39,7 @@ class AuthenticateUserService {
const passwordMatched = await compare(password, user.password);
if (!passwordMatched) {
throw new AppError('Incorrect login/password combination.', 200);
throw new AppError(failedLoginMessage.message, failedLoginMessage.statusCode);
}
// usuário autenticado

View File

@@ -13,7 +13,7 @@ class CreateUserService {
});
if (!user) {
throw new AppError('User does not exist.');
throw new AppError('Usuário não existe.');
}
return user;

2388
yarn.lock

File diff suppressed because it is too large Load Diff