mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix: missed transaction
This commit is contained in:
@@ -12,9 +12,12 @@ export type TTokenDALFactory = ReturnType<typeof tokenDALFactory>;
|
|||||||
export const tokenDALFactory = (db: TDbClient) => {
|
export const tokenDALFactory = (db: TDbClient) => {
|
||||||
const authOrm = ormify(db, TableName.AuthTokens);
|
const authOrm = ormify(db, TableName.AuthTokens);
|
||||||
|
|
||||||
const findOneTokenSession = async (filter: Partial<TAuthTokenSessions>): Promise<TAuthTokenSessions | undefined> => {
|
const findOneTokenSession = async (
|
||||||
|
filter: Partial<TAuthTokenSessions>,
|
||||||
|
tx?: Knex
|
||||||
|
): Promise<TAuthTokenSessions | undefined> => {
|
||||||
try {
|
try {
|
||||||
const doc = await db.replicaNode()(TableName.AuthTokenSession).where(filter).first();
|
const doc = await (tx || db.replicaNode())(TableName.AuthTokenSession).where(filter).first();
|
||||||
return doc;
|
return doc;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "FindOneTokenSession" });
|
throw new DatabaseError({ error, name: "FindOneTokenSession" });
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgMembershipDAL }: TAu
|
|||||||
{ userId, ip, userAgent }: TIssueAuthTokenDTO,
|
{ userId, ip, userAgent }: TIssueAuthTokenDTO,
|
||||||
tx?: Knex
|
tx?: Knex
|
||||||
): Promise<TAuthTokenSessions | undefined> => {
|
): Promise<TAuthTokenSessions | undefined> => {
|
||||||
let session = await tokenDAL.findOneTokenSession({ userId, ip, userAgent });
|
let session = await tokenDAL.findOneTokenSession({ userId, ip, userAgent }, tx);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
session = await tokenDAL.insertTokenSession(userId, ip, userAgent, tx);
|
session = await tokenDAL.insertTokenSession(userId, ip, userAgent, tx);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user