fix: safely access user in auth operations (#8381)

This commit is contained in:
Alessio Gravili
2024-09-23 16:46:43 -04:00
committed by GitHub
parent dc69e2c0f6
commit a80f5b65ec
3 changed files with 11 additions and 4 deletions

View File

@@ -173,13 +173,14 @@ export const loginOperation = async <TSlug extends CollectionSlug>(
req,
where: whereConstraint,
})
user.collection = collectionConfig.slug
if (!user || (args.collection.config.auth.verify && user._verified === false)) {
throw new AuthenticationError(req.t, Boolean(canLoginWithUsername && sanitizedUsername))
}
if (user && isLocked(new Date(user.lockUntil).getTime())) {
user.collection = collectionConfig.slug
if (isLocked(new Date(user.lockUntil).getTime())) {
throw new LockedAuth(req.t)
}

View File

@@ -37,7 +37,10 @@ export const meOperation = async (args: Arguments): Promise<MeOperationResult> =
req,
showHiddenFields: false,
})) as User
if (user) {
user.collection = collection.config.slug
}
if (req.user.collection !== collection.config.slug) {
return {

View File

@@ -75,7 +75,10 @@ export const refreshOperation = async (incomingArgs: Arguments): Promise<Result>
depth: isGraphQL ? 0 : args.collection.config.auth.depth,
req: args.req,
})
if (user) {
user.collection = args.req.user.collection
}
let result: Result