feat: added last login time

This commit is contained in:
=
2025-08-07 13:37:06 +05:30
parent be20a507ac
commit eebf080e3c
29 changed files with 156 additions and 63 deletions
@@ -149,7 +149,10 @@ export const authLoginServiceFactory = ({
if (organizationId) {
const org = await orgDAL.findById(organizationId);
if (org) {
await orgMembershipDAL.update({ userId: user.id, orgId: org.id }, { lastLoggedInAuthMethod: authMethod });
await orgMembershipDAL.update(
{ userId: user.id, orgId: org.id },
{ lastLoginAuthMethod: authMethod, lastLoginTime: new Date() }
);
if (org.userTokenExpiration) {
tokenSessionExpiresIn = getMinExpiresIn(cfg.JWT_AUTH_LIFETIME, org.userTokenExpiration);
refreshTokenExpiresIn = org.userTokenExpiration;
@@ -32,8 +32,8 @@ import {
keyAlgorithmToAlgCfg
} from "../certificate-authority-fns";
import { TCertificateAuthoritySecretDALFactory } from "../certificate-authority-secret-dal";
import { TIssueCertWithTemplateDTO } from "./internal-certificate-authority-types";
import { validateAndMapAltNameType } from "../certificate-authority-validators";
import { TIssueCertWithTemplateDTO } from "./internal-certificate-authority-types";
type TInternalCertificateAuthorityFnsDeps = {
certificateAuthorityDAL: Pick<TCertificateAuthorityDALFactory, "findByIdWithAssociatedCa" | "findById">;
@@ -52,6 +52,7 @@ import {
} from "../certificate-authority-fns";
import { TCertificateAuthorityQueueFactory } from "../certificate-authority-queue";
import { TCertificateAuthoritySecretDALFactory } from "../certificate-authority-secret-dal";
import { validateAndMapAltNameType } from "../certificate-authority-validators";
import { TInternalCertificateAuthorityDALFactory } from "./internal-certificate-authority-dal";
import {
TCreateCaDTO,
@@ -68,7 +69,6 @@ import {
TSignIntermediateDTO,
TUpdateCaDTO
} from "./internal-certificate-authority-types";
import { validateAndMapAltNameType } from "../certificate-authority-validators";
type TInternalCertificateAuthorityServiceFactoryDep = {
certificateAuthorityDAL: Pick<
@@ -64,6 +64,8 @@ export const identityAliCloudAuthServiceFactory = ({
identityId: identityAliCloudAuth.identityId
});
if (!identityMembershipOrg) throw new UnauthorizedError({ message: "Identity not attached to a organization" });
const requestUrl = new URL("https://sts.aliyuncs.com");
for (const key of Object.keys(params)) {
@@ -90,7 +92,8 @@ export const identityAliCloudAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.ALICLOUD_AUTH
lastLoginAuthMethod: IdentityAuthMethod.ALICLOUD_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -91,6 +91,7 @@ export const identityAwsAuthServiceFactory = ({
}
const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId: identityAwsAuth.identityId });
if (!identityMembershipOrg) throw new UnauthorizedError({ message: "Identity not attached to a organization" });
const headers: TAwsGetCallerIdentityHeaders = JSON.parse(Buffer.from(iamRequestHeaders, "base64").toString());
const body: string = Buffer.from(iamRequestBody, "base64").toString();
@@ -155,7 +156,8 @@ export const identityAwsAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.AWS_AUTH
lastLoginAuthMethod: IdentityAuthMethod.AWS_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -83,7 +83,8 @@ export const identityAzureAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.AZURE_AUTH
lastLoginAuthMethod: IdentityAuthMethod.AZURE_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -122,7 +122,8 @@ export const identityGcpAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.GCP_AUTH
lastLoginAuthMethod: IdentityAuthMethod.GCP_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -212,7 +212,8 @@ export const identityJwtAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.JWT_AUTH
lastLoginAuthMethod: IdentityAuthMethod.JWT_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -383,7 +383,8 @@ export const identityKubernetesAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.KUBERNETES_AUTH
lastLoginAuthMethod: IdentityAuthMethod.KUBERNETES_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -147,7 +147,8 @@ export const identityLdapAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.LDAP_AUTH
lastLoginAuthMethod: IdentityAuthMethod.LDAP_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -57,6 +57,7 @@ export const identityOciAuthServiceFactory = ({
}
const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId: identityOciAuth.identityId });
if (!identityMembershipOrg) throw new UnauthorizedError({ message: "Identity not attached to a organization" });
// Validate OCI host format. Ensures that the host is in "identity.<region>.oraclecloud.com" format.
if (!headers.host || !new RE2("^identity\\.([a-z]{2}-[a-z]+-[1-9])\\.oraclecloud\\.com$").test(headers.host)) {
@@ -94,7 +95,8 @@ export const identityOciAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.OCI_AUTH
lastLoginAuthMethod: IdentityAuthMethod.OCI_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -181,7 +181,8 @@ export const identityOidcAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.OIDC_AUTH
lastLoginAuthMethod: IdentityAuthMethod.OIDC_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -121,7 +121,8 @@ export const identityTlsCertAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.TLS_CERT_AUTH
lastLoginAuthMethod: IdentityAuthMethod.TLS_CERT_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -348,7 +348,8 @@ export const identityTokenAuthServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.TOKEN_AUTH
lastLoginAuthMethod: IdentityAuthMethod.TOKEN_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -135,7 +135,8 @@ export const identityUaServiceFactory = ({
await identityOrgMembershipDAL.updateById(
identityMembershipOrg.id,
{
lastLoggedInAuthMethod: IdentityAuthMethod.UNIVERSAL_AUTH
lastLoginAuthMethod: IdentityAuthMethod.UNIVERSAL_AUTH,
lastLoginTime: new Date()
},
tx
);
@@ -254,7 +254,8 @@ export const identityOrgDALFactory = (db: TDbClient) => {
db.ref("role").withSchema("paginatedIdentity"),
db.ref("roleId").withSchema("paginatedIdentity"),
db.ref("orgId").withSchema("paginatedIdentity"),
db.ref("lastLoggedInAuthMethod").withSchema("paginatedIdentity"),
db.ref("lastLoginAuthMethod").withSchema("paginatedIdentity"),
db.ref("lastLoginTime").withSchema("paginatedIdentity"),
db.ref("createdAt").withSchema("paginatedIdentity"),
db.ref("updatedAt").withSchema("paginatedIdentity"),
db.ref("identityId").withSchema("paginatedIdentity").as("identityId"),
@@ -321,7 +322,8 @@ export const identityOrgDALFactory = (db: TDbClient) => {
tlsCertId,
createdAt,
updatedAt,
lastLoggedInAuthMethod
lastLoginAuthMethod,
lastLoginTime
}) => ({
role,
roleId,
@@ -330,7 +332,8 @@ export const identityOrgDALFactory = (db: TDbClient) => {
orgId,
createdAt,
updatedAt,
lastLoggedInAuthMethod,
lastLoginAuthMethod,
lastLoginTime,
customRole: roleId
? {
id: crId,
@@ -500,7 +503,8 @@ export const identityOrgDALFactory = (db: TDbClient) => {
db.ref("orgId").withSchema(TableName.IdentityOrgMembership),
db.ref("createdAt").withSchema(TableName.IdentityOrgMembership),
db.ref("updatedAt").withSchema(TableName.IdentityOrgMembership),
db.ref("lastLoggedInAuthMethod").withSchema(TableName.IdentityOrgMembership),
db.ref("lastLoginAuthMethod").withSchema(TableName.IdentityOrgMembership),
db.ref("lastLoginTime").withSchema(TableName.IdentityOrgMembership),
db.ref("identityId").withSchema(TableName.IdentityOrgMembership).as("identityId"),
db.ref("name").withSchema(TableName.Identity).as("identityName"),
db.ref("hasDeleteProtection").withSchema(TableName.Identity),
@@ -535,10 +539,10 @@ export const identityOrgDALFactory = (db: TDbClient) => {
} else if (orderBy === OrgIdentityOrderBy.Role) {
void query.orderByRaw(
`
CASE
WHEN ??.role = ?
THEN ??.slug
ELSE ??.role
CASE
WHEN ??.role = ?
THEN ??.slug
ELSE ??.role
END ?
`,
[
@@ -581,7 +585,8 @@ export const identityOrgDALFactory = (db: TDbClient) => {
ldapId,
createdAt,
updatedAt,
lastLoggedInAuthMethod
lastLoginTime,
lastLoginAuthMethod
}) => ({
role,
roleId,
@@ -591,7 +596,8 @@ export const identityOrgDALFactory = (db: TDbClient) => {
orgId,
createdAt,
updatedAt,
lastLoggedInAuthMethod,
lastLoginTime,
lastLoginAuthMethod,
customRole: roleId
? {
id: crId,
@@ -32,7 +32,8 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
db.ref("roleId").withSchema(TableName.OrgMembership),
db.ref("status").withSchema(TableName.OrgMembership),
db.ref("isActive").withSchema(TableName.OrgMembership),
db.ref("lastLoggedInAuthMethod").withSchema(TableName.OrgMembership),
db.ref("lastLoginAuthMethod").withSchema(TableName.OrgMembership),
db.ref("lastLoginTime").withSchema(TableName.OrgMembership),
db.ref("email").withSchema(TableName.Users),
db.ref("username").withSchema(TableName.Users),
db.ref("firstName").withSchema(TableName.Users),
@@ -66,7 +67,8 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
status,
isActive,
inviteEmail,
lastLoggedInAuthMethod
lastLoginAuthMethod,
lastLoginTime
}) => ({
roleId,
orgId,
@@ -75,7 +77,8 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
status,
isActive,
inviteEmail,
lastLoggedInAuthMethod,
lastLoginAuthMethod,
lastLoginTime,
user: {
id: userId,
email,
+2 -1
View File
@@ -285,7 +285,8 @@ export const orgDALFactory = (db: TDbClient) => {
db.ref("roleId").withSchema(TableName.OrgMembership),
db.ref("status").withSchema(TableName.OrgMembership),
db.ref("isActive").withSchema(TableName.OrgMembership),
db.ref("lastLoggedInAuthMethod").withSchema(TableName.OrgMembership),
db.ref("lastLoginAuthMethod").withSchema(TableName.OrgMembership),
db.ref("lastLoginTime").withSchema(TableName.OrgMembership),
db.ref("email").withSchema(TableName.Users),
db.ref("isEmailVerified").withSchema(TableName.Users),
db.ref("username").withSchema(TableName.Users),