Skip to content

Commit

Permalink
Add: update last_login column of user on login
Browse files Browse the repository at this point in the history
  • Loading branch information
georgipavlov-7DIGIT committed Apr 10, 2024
1 parent f4521d4 commit 44c7f53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion service/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import {
tooManyLoginRequests,
} from "#utils/errors";
import { produceRaiseNotification } from "#utils/kafkaProducers";
import { getFailedLoginAttempts, isJwtBlacklisted } from "#queries/auth";
import {
getFailedLoginAttempts,
isJwtBlacklisted,
updateLastLoginQuery,
} from "#queries/auth";

const localStrategy = passportLocal.Strategy;
const jwtStrategy = passportJWT.Strategy;
Expand Down Expand Up @@ -307,6 +311,13 @@ passport.use(
return done(incorrectCredentials(language));
}

await updateLastLoginQuery({
poolCountry: country,
userId: user.user_id,
}).catch((err) => {
console.log("Error updating last login", err);
});

if (userType === "provider") {
return done(null, user);

Expand Down
12 changes: 12 additions & 0 deletions service/queries/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ export const getFailedLoginAttempts = async ({ poolCountry, userId }) => {
[userId]
);
};

export const updateLastLoginQuery = async ({ poolCountry, userId }) => {
return await getDBPool("piiDb", poolCountry).query(
`
UPDATE "user"
SET last_login = NOW()
WHERE user_id = $1
RETURNING *;
`,
[userId]
);
};

0 comments on commit 44c7f53

Please sign in to comment.