mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-21 09:28:14 +00:00
feat: changed req.auth.userId to permission.id to satisfy type error
This commit is contained in:
@@ -25,7 +25,7 @@ export const registerAuthRoutes = async (server: FastifyZodProvider) => {
|
||||
handler: async (req, res) => {
|
||||
const appCfg = getConfig();
|
||||
if (req.auth.authMode === AuthMode.JWT) {
|
||||
await server.services.login.logout(req.auth.userId, req.auth.tokenVersionId);
|
||||
await server.services.login.logout(req.permission.id, req.auth.tokenVersionId);
|
||||
}
|
||||
res.cookie("jid", "", {
|
||||
httpOnly: true,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
|
||||
import { UsersSchema } from "@app/db/schemas";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
import { ActorType, AuthMode } from "@app/services/auth/auth-type";
|
||||
|
||||
export const registerInviteOrgRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
@@ -22,9 +22,10 @@ export const registerInviteOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.actor !== ActorType.USER) return;
|
||||
const completeInviteLink = await server.services.org.inviteUserToOrganization({
|
||||
orgId: req.body.organizationId,
|
||||
userId: req.auth.userId,
|
||||
userId: req.permission.id,
|
||||
inviteeEmail: req.body.inviteeEmail
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const organizations = await server.services.org.findAllOrganizationOfUser(req.auth.userId);
|
||||
const organizations = await server.services.org.findAllOrganizationOfUser(req.permission.id);
|
||||
return { organizations };
|
||||
}
|
||||
});
|
||||
@@ -43,7 +43,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const organization = await server.services.org.findOrganizationById(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId
|
||||
);
|
||||
return { organization };
|
||||
@@ -77,7 +77,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const users = await server.services.org.findAllOrgMembers(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId
|
||||
);
|
||||
return { users };
|
||||
@@ -102,7 +102,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const organization = await server.services.org.updateOrgName(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId,
|
||||
req.body.name
|
||||
);
|
||||
@@ -127,7 +127,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const incidentContactsOrg = await req.server.services.org.findIncidentContacts(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId
|
||||
);
|
||||
return { incidentContactsOrg };
|
||||
@@ -149,7 +149,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const incidentContactsOrg = await req.server.services.org.createIncidentContact(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId,
|
||||
req.body.email
|
||||
);
|
||||
@@ -172,7 +172,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const incidentContactsOrg = await req.server.services.org.deleteIncidentContact(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId,
|
||||
req.params.incidentContactId
|
||||
);
|
||||
|
||||
@@ -23,7 +23,7 @@ export const registerPasswordRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const { salt, serverPublicKey } = await server.services.password.generateServerPubKey(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.body.clientPublicKey
|
||||
);
|
||||
return { salt, serverPublicKey };
|
||||
@@ -54,7 +54,7 @@ export const registerPasswordRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req, res) => {
|
||||
const appCfg = getConfig();
|
||||
await server.services.password.changePassword({ ...req.body, userId: req.auth.userId });
|
||||
await server.services.password.changePassword({ ...req.body, userId: req.permission.id });
|
||||
|
||||
res.cookie("jid", appCfg.COOKIE_SECRET_SIGN_KEY, {
|
||||
httpOnly: true,
|
||||
@@ -89,7 +89,7 @@ export const registerPasswordRouter = async (server: FastifyZodProvider) => {
|
||||
handler: async (req) => {
|
||||
const backupPrivateKey = await server.services.password.createBackupPrivateKey({
|
||||
...req.body,
|
||||
userId: req.auth.userId
|
||||
userId: req.permission.id
|
||||
});
|
||||
if (!backupPrivateKey) throw new Error("Failed to create backup key");
|
||||
|
||||
@@ -111,7 +111,7 @@ export const registerPasswordRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
handler: async (req) => {
|
||||
const backupPrivateKey = await server.services.password.getBackupPrivateKeyOfUser(
|
||||
req.auth.userId
|
||||
req.permission.id
|
||||
);
|
||||
if (!backupPrivateKey) throw new Error("Failed to find backup key");
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export const registerUserActionRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const userAction = await server.services.user.createUserAction(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.body.action
|
||||
);
|
||||
return { userAction, message: "Successfully recorded user action" };
|
||||
@@ -45,7 +45,7 @@ export const registerUserActionRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const userAction = await server.services.user.getUserAction(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.query.action
|
||||
);
|
||||
return { userAction };
|
||||
|
||||
@@ -17,7 +17,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const user = await server.services.user.getMe(req.auth.userId);
|
||||
const user = await server.services.user.getMe(req.permission.id);
|
||||
return { user };
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
UsersSchema
|
||||
} from "@app/db/schemas";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
import { ActorType, AuthMode } from "@app/services/auth/auth-type";
|
||||
|
||||
export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
@@ -36,8 +36,10 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.actor !== ActorType.USER) return;
|
||||
|
||||
const users = await server.services.org.findAllOrgMembers(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId
|
||||
);
|
||||
return { users };
|
||||
@@ -60,8 +62,10 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.actor !== ActorType.USER) return;
|
||||
|
||||
const membership = await server.services.org.updateOrgMembership({
|
||||
userId: req.auth.userId,
|
||||
userId: req.permission.id,
|
||||
role: req.body.role,
|
||||
orgId: req.params.organizationId,
|
||||
membershipId: req.params.membershipId
|
||||
@@ -83,8 +87,10 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.actor !== ActorType.USER) return;
|
||||
|
||||
const membership = await server.services.org.deleteOrgMembership({
|
||||
userId: req.auth.userId,
|
||||
userId: req.permission.id,
|
||||
orgId: req.params.organizationId,
|
||||
membershipId: req.params.membershipId
|
||||
});
|
||||
@@ -107,8 +113,10 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.actor !== ActorType.USER) return;
|
||||
|
||||
const organization = await server.services.org.createOrganization(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.body.name
|
||||
);
|
||||
return { organization };
|
||||
@@ -130,8 +138,10 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.actor !== ActorType.USER) return;
|
||||
|
||||
const organization = await server.services.org.deleteOrganizationById(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.organizationId
|
||||
);
|
||||
return { organization };
|
||||
|
||||
@@ -26,7 +26,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
preHandler: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),
|
||||
handler: async (req) => {
|
||||
const user = await server.services.user.toggleUserMfa(req.auth.userId, req.body.isMfaEnabled);
|
||||
const user = await server.services.user.toggleUserMfa(req.permission.id, req.body.isMfaEnabled);
|
||||
return { user };
|
||||
}
|
||||
});
|
||||
@@ -48,7 +48,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
preHandler: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),
|
||||
handler: async (req) => {
|
||||
const user = await server.services.user.updateUserName(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.body.firstName,
|
||||
req.body.lastName
|
||||
);
|
||||
@@ -72,7 +72,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
preHandler: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),
|
||||
handler: async (req) => {
|
||||
const user = await server.services.user.updateAuthMethods(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.body.authMethods
|
||||
);
|
||||
return { user };
|
||||
@@ -91,7 +91,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),
|
||||
handler: async (req) => {
|
||||
const organizations = await server.services.org.findAllOrganizationOfUser(req.auth.userId);
|
||||
const organizations = await server.services.org.findAllOrganizationOfUser(req.permission.id);
|
||||
return { organizations };
|
||||
}
|
||||
});
|
||||
@@ -106,7 +106,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const apiKeys = await server.services.apiKey.getMyApiKeys(req.auth.userId);
|
||||
const apiKeys = await server.services.apiKey.getMyApiKeys(req.permission.id);
|
||||
return apiKeys;
|
||||
}
|
||||
});
|
||||
@@ -129,7 +129,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const apiKeys = await server.services.apiKey.createApiKey(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.body.name,
|
||||
req.body.expiresIn
|
||||
);
|
||||
@@ -153,7 +153,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const apiKeyData = await server.services.apiKey.deleteApiKey(
|
||||
req.auth.userId,
|
||||
req.permission.id,
|
||||
req.params.apiKeyDataId
|
||||
);
|
||||
return { apiKeyData };
|
||||
@@ -170,7 +170,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const sessions = await server.services.authToken.getTokenSessionByUser(req.auth.userId);
|
||||
const sessions = await server.services.authToken.getTokenSessionByUser(req.permission.id);
|
||||
return sessions;
|
||||
}
|
||||
});
|
||||
@@ -187,7 +187,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
await server.services.authToken.revokeAllMySessions(req.auth.userId);
|
||||
await server.services.authToken.revokeAllMySessions(req.permission.id);
|
||||
return {
|
||||
message: "Successfully revoked all sessions"
|
||||
};
|
||||
@@ -206,7 +206,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const user = await server.services.user.getMe(req.auth.userId);
|
||||
const user = await server.services.user.getMe(req.permission.id);
|
||||
return { user };
|
||||
}
|
||||
});
|
||||
@@ -223,7 +223,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const user = await server.services.user.deleteMe(req.auth.userId);
|
||||
const user = await server.services.user.deleteMe(req.permission.id);
|
||||
return { user };
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
const apiKeyData = await server.services.apiKey.getMyApiKeys(req.auth.userId);
|
||||
const apiKeyData = await server.services.apiKey.getMyApiKeys(req.permission.id);
|
||||
return { apiKeyData };
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user