Skip to main content
Version: ๐Ÿšง Canary

โœ… Identity validators

Identity routes compose two shared access factories, while isSelf is the local reusable ownership validator. Validators receive the route payload, either complete normally or throw NodeblocksError; they are SDK guards, not Express middleware.

Inventoryโ€‹

ValidatorReadsSuccess conditionFailure / errorConsumers
isSelfcontext.authenticate or Bearer fallback; configured payload pathTarget value equals the valid user tokenโ€™s identityId401 invalid token; 403 missing or mismatched targetAuthentication, Profile, Order, Organization, Notification, and Chat routes.
isAuthenticated()context.authenticate or Bearer fallbackSelected adapter resolvesAdapter error propagatesfind, get, update, delete, lock, unlock
checkIdentityType(['admin'])auth adapter, db.identities, configuration.identity.typeIdsValid user tokenโ€™s loaded identity has configured admin type ID500 setup; 401 invalid token; 403 identity/typefind, get, update, delete, lock, unlock

Detailsโ€‹

isSelfโ€‹

Implementation

Signature: isSelf<T extends string>(identityIdPathInPayload: [T, ...T[]]): Validator. This factory selects context.authenticate or getBearerTokenInfo, calls it with the route payload, requires isValidUserAccessToken(tokenInfo), then reads path(identityIdPathInPayload, payload) with ramda. It compares that configured target valueโ€”not necessarily a field named identityIdโ€”with tokenInfo.identityId.

It throws NodeblocksError(401, 'Invalid token', 'isSelf') for a non-user token, NodeblocksError(403, 'Identity ID is required', 'isSelf') when the configured path has no value, and NodeblocksError(403, 'Identity ID does not match', 'isSelf') when the values differ.

Consumers: isSelf(...) is the self branch of some(checkIdentityType(['admin']), isSelf(...)) on Authenticationโ€™s deleteRefreshTokensRoute, sendVerificationEmailRoute, changeEmailRoute, changePasswordRoute, and deactivateRoute, each with ['params', 'requestParams', 'identityId'] except deactivationโ€™s ['params', 'requestBody', 'identityId']; Profileโ€™s createProfileRoute with body identityId; Orderโ€™s createOrderRoute with body identityId and findOrdersRoute with query identityId; Organizationโ€™s findOrganizationsForMemberRoute with path identityId; and Chatโ€™s createChatChannelRoute, findChatChannelsRoute, createChatSubscriptionRoute, and findChatSubscriptionsRoute. It runs directly on Profileโ€™s findProfilesByIdentityIdRoute (path identityId; see Profile routes), Notificationโ€™s findNotificationsRoute and updateNotificationToReadBatchRoute, Chatโ€™s createChatMessageRoute, findChatMessagesRoute, and upsertChatChannelReadStateRoute. Chat uses ownerId, subscribedId, and senderId respectively; the remaining direct routes use identityId at the stated body, path, or query location.

Identity routes do not compose isSelf; they use the administrator check below.

isAuthenticated()โ€‹

Implementation

checkIdentityType(['admin'])โ€‹

Implementation

This shared factory is documented canonically in Common validators. Identityโ€™s exact invocation is checkIdentityType(['admin']). It requires context.db.identities and context.configuration.identity.typeIds, selects context.authenticate or getBearerTokenInfo, requires a valid user access token, loads tokenInfo.identityId using getIdentityById, then compares the retrieved identityโ€™s typeId with identityTypeIds.admin.

It throws 500 db.identities is not set or 500 configuration.identity.typeIds is not set; 401 Invalid token; 403 Failed to fetch identity, 403 Invalid identity type ID, or 403 Identity is not authorized to access this resource.

Consumers: Identity invokes checkIdentityType(['admin']) after isAuthenticated() on findIdentitiesRoute, getIdentityRoute, updateIdentityRoute, deleteIdentityRoute, lockIdentityRoute, and unlockIdentityRoute. Other direct ['admin'] consumers are Attribute createAttributeRoute, updateAttributeRoute, deleteAttributeRoute; all Organization routes in the route reference; all Profile routes except findProfilesByIdentityIdRoute; all Order routes except findOrdersByOrganizationIdRoute; Location createLocationRoute, updateLocationRoute, deleteLocationRoute; Authentication deleteRefreshTokensRoute, generateOnetimeTokenRoute, restoreOnetimeTokenRoute, invalidateOnetimeTokenRoute, sendVerificationEmailRoute, changeEmailRoute, changePasswordRoute, deactivateRoute, activateRoute; all administrator Product routes; all Invitation routes; the administrator Chat channel, message, template, and subscription routes; and all Category routes.