Skip to content

Commit c36eb0c

Browse files
feat(api): update lastLoggedAt if external user authenticates with Pix Authentication Methods
1 parent 2f84e90 commit c36eb0c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

api/lib/domain/usecases/authenticate-external-user.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ async function authenticateExternalUser({
5757
const token = tokenService.createAccessTokenForSaml({ userId: userFromCredentials.id, audience });
5858

5959
await userLoginRepository.updateLastLoggedAt({ userId: userFromCredentials.id });
60-
60+
await authenticationMethodRepository.updateLastLoggedAtByIdentityProvider({
61+
userId: userFromCredentials.id,
62+
identityProvider: NON_OIDC_IDENTITY_PROVIDERS.PIX.code,
63+
});
6164
return token;
6265
} catch (error) {
6366
if (error instanceof UserNotFoundError || error instanceof PasswordNotMatching) {

api/tests/unit/domain/usecases/authenticate-external-user_test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('Unit | Application | UseCase | authenticate-external-user', function (
3636
};
3737
authenticationMethodRepository = {
3838
create: sinon.stub(),
39+
updateLastLoggedAtByIdentityProvider: sinon.stub(),
3940
};
4041
userRepository = {
4142
getBySamlId: sinon.stub(),
@@ -107,7 +108,6 @@ describe('Unit | Application | UseCase | authenticate-external-user', function (
107108

108109
const expectedToken = 'expected returned token';
109110
tokenService.createAccessTokenForSaml.withArgs({ userId: user.id, audience }).resolves(expectedToken);
110-
111111
// when
112112
await authenticateExternalUser({
113113
username: user.email,
@@ -125,6 +125,10 @@ describe('Unit | Application | UseCase | authenticate-external-user', function (
125125

126126
// then
127127
expect(userLoginRepository.updateLastLoggedAt).to.have.been.calledWithExactly({ userId: user.id });
128+
expect(authenticationMethodRepository.updateLastLoggedAtByIdentityProvider).to.have.been.calledWithExactly({
129+
userId: user.id,
130+
identityProvider: NON_OIDC_IDENTITY_PROVIDERS.PIX.code,
131+
});
128132
});
129133

130134
it("should throw an UnexpectedUserAccountError (with expected user's username or email) when the authenticated user does not match the expected one", async function () {

0 commit comments

Comments
 (0)