fix: feeds collectionSlug through me auth for graphql resolver

This commit is contained in:
Jacob Fletcher
2021-04-14 12:41:40 -04:00
parent 204b755201
commit 9ee2f9c0dc
4 changed files with 24 additions and 8 deletions

View File

@@ -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;

View File

@@ -11,17 +11,20 @@ export type Result = {
}
export type Arguments = {
req: PayloadRequest
req: PayloadRequest,
collectionSlug: string
}
async function me({ req }: Arguments): Promise<Result> {
async function me({
req,
collectionSlug,
}: Arguments): Promise<Result> {
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,
};

View File

@@ -3,7 +3,11 @@ import { PayloadRequest } from '../../express/types';
export default async function me(req: PayloadRequest, res: Response, next: NextFunction): Promise<any> {
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);

View File

@@ -198,7 +198,7 @@ function registerCollections(): void {
},
},
}),
resolve: me,
resolve: me(slug),
};
if (collection.config.auth.maxLoginAttempts > 0) {