diff --git a/src/auth/graphql/resolvers/me.ts b/src/auth/graphql/resolvers/me.ts index dcde5b51d8..391a09b773 100644 --- a/src/auth/graphql/resolvers/me.ts +++ b/src/auth/graphql/resolvers/me.ts @@ -1,5 +1,14 @@ -async function me(_, __, context) { - return this.operations.collections.auth.me({ req: context.req }); +function me(collectionSlug: string): any { + async function resolver(_, __, context) { + return this.operations.collections.auth.me({ + req: context.req, + collectionSlug, + }); + } + + const meResolver = resolver.bind(this); + + return meResolver; } export default me; diff --git a/src/auth/operations/me.ts b/src/auth/operations/me.ts index 0a7876504d..3ec37c8ad1 100644 --- a/src/auth/operations/me.ts +++ b/src/auth/operations/me.ts @@ -11,17 +11,20 @@ export type Result = { } export type Arguments = { - req: PayloadRequest + req: PayloadRequest, + collectionSlug: string } -async function me({ req }: Arguments): Promise { +async function me({ + req, + collectionSlug, +}: Arguments): Promise { const extractJWT = getExtractJWT(this.config); if (req.user) { - const requestedSlug = req.route.path.split('/').filter((r) => r !== '')[0]; const user = { ...req.user }; - if (user.collection !== requestedSlug) { + if (user.collection !== collectionSlug) { return { user: null, }; diff --git a/src/auth/requestHandlers/me.ts b/src/auth/requestHandlers/me.ts index bda1f02b5c..936882d720 100644 --- a/src/auth/requestHandlers/me.ts +++ b/src/auth/requestHandlers/me.ts @@ -3,7 +3,11 @@ import { PayloadRequest } from '../../express/types'; export default async function me(req: PayloadRequest, res: Response, next: NextFunction): Promise { try { - const response = await this.operations.collections.auth.me({ req }); + const collectionSlug = req.route.path.split('/').filter((r) => r !== '')[0]; + const response = await this.operations.collections.auth.me({ + req, + collectionSlug, + }); return res.status(200).json(response); } catch (err) { return next(err); diff --git a/src/collections/graphql/init.ts b/src/collections/graphql/init.ts index 902c73f646..5b4411c9dc 100644 --- a/src/collections/graphql/init.ts +++ b/src/collections/graphql/init.ts @@ -198,7 +198,7 @@ function registerCollections(): void { }, }, }), - resolve: me, + resolve: me(slug), }; if (collection.config.auth.maxLoginAttempts > 0) {