mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 15:40:47 +00:00
feat: changed line length to 120
This commit is contained in:
@@ -12,9 +12,7 @@ export type TTokenDALFactory = ReturnType<typeof tokenDALFactory>;
|
||||
export const tokenDALFactory = (db: TDbClient) => {
|
||||
const authOrm = ormify(db, TableName.AuthTokens);
|
||||
|
||||
const findOneTokenSession = async (
|
||||
filter: Partial<TAuthTokenSessions>
|
||||
): Promise<TAuthTokenSessions | undefined> => {
|
||||
const findOneTokenSession = async (filter: Partial<TAuthTokenSessions>): Promise<TAuthTokenSessions | undefined> => {
|
||||
try {
|
||||
const doc = await db(TableName.AuthTokenSession).where(filter).first();
|
||||
return doc;
|
||||
@@ -29,20 +27,14 @@ export const tokenDALFactory = (db: TDbClient) => {
|
||||
orgId
|
||||
}: TDeleteTokenForUserDALDTO): Promise<TAuthTokens[] | undefined> => {
|
||||
try {
|
||||
const doc = await db(TableName.AuthTokens)
|
||||
.where({ userId, type, orgId })
|
||||
.delete()
|
||||
.returning("*");
|
||||
const doc = await db(TableName.AuthTokens).where({ userId, type, orgId }).delete().returning("*");
|
||||
return doc;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "DeleteTokenForUser" });
|
||||
}
|
||||
};
|
||||
|
||||
const decrementTriesField = async ({
|
||||
userId,
|
||||
type
|
||||
}: TDeleteTokenForUserDALDTO): Promise<void> => {
|
||||
const decrementTriesField = async ({ userId, type }: TDeleteTokenForUserDALDTO): Promise<void> => {
|
||||
try {
|
||||
await db(TableName.AuthTokens).where({ userId, type }).decrement("triesLeft", 1);
|
||||
} catch (error) {
|
||||
@@ -99,10 +91,7 @@ export const tokenDALFactory = (db: TDbClient) => {
|
||||
|
||||
const deleteTokenSession = async (filter: Partial<TAuthTokenSessions>, tx?: Knex) => {
|
||||
try {
|
||||
const sessions = await (tx || db)(TableName.AuthTokenSession)
|
||||
.where(filter)
|
||||
.del()
|
||||
.returning("*");
|
||||
const sessions = await (tx || db)(TableName.AuthTokenSession).where(filter).del().returning("*");
|
||||
return sessions;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ name: "Delete token session", error });
|
||||
|
||||
@@ -9,12 +9,7 @@ import { UnauthorizedError } from "@app/lib/errors";
|
||||
import { AuthModeJwtTokenPayload } from "../auth/auth-type";
|
||||
import { TUserDALFactory } from "../user/user-dal";
|
||||
import { TTokenDALFactory } from "./auth-token-dal";
|
||||
import {
|
||||
TCreateTokenForUserDTO,
|
||||
TIssueAuthTokenDTO,
|
||||
TokenType,
|
||||
TValidateTokenForUserDTO
|
||||
} from "./auth-token-types";
|
||||
import { TCreateTokenForUserDTO, TIssueAuthTokenDTO, TokenType, TValidateTokenForUserDTO } from "./auth-token-types";
|
||||
|
||||
type TAuthTokenServiceFactoryDep = {
|
||||
tokenDAL: TTokenDALFactory;
|
||||
@@ -125,14 +120,10 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL }: TAuthTokenServiceFact
|
||||
return session;
|
||||
};
|
||||
|
||||
const clearTokenSessionById = async (
|
||||
userId: string,
|
||||
sessionId: string
|
||||
): Promise<TAuthTokenSessions | undefined> =>
|
||||
const clearTokenSessionById = async (userId: string, sessionId: string): Promise<TAuthTokenSessions | undefined> =>
|
||||
tokenDAL.incrementTokenSessionVersion(userId, sessionId);
|
||||
|
||||
const getUserTokenSessionById = async (id: string, userId: string) =>
|
||||
tokenDAL.findOneTokenSession({ id, userId });
|
||||
const getUserTokenSessionById = async (id: string, userId: string) => tokenDAL.findOneTokenSession({ id, userId });
|
||||
|
||||
const getTokenSessionByUser = async (userId: string) => tokenDAL.findTokenSessions({ userId });
|
||||
|
||||
@@ -145,8 +136,7 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL }: TAuthTokenServiceFact
|
||||
userId: token.userId
|
||||
});
|
||||
if (!session) throw new UnauthorizedError({ name: "Session not found" });
|
||||
if (token.accessVersion !== session.accessVersion)
|
||||
throw new UnauthorizedError({ name: "Stale session" });
|
||||
if (token.accessVersion !== session.accessVersion) throw new UnauthorizedError({ name: "Stale session" });
|
||||
|
||||
const user = await userDAL.findById(session.userId);
|
||||
if (!user || !user.isAccepted) throw new UnauthorizedError({ name: "Token user not found" });
|
||||
|
||||
Reference in New Issue
Block a user