fix: feeds collectionSlug through me auth for graphql resolver
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -198,7 +198,7 @@ function registerCollections(): void {
|
||||
},
|
||||
},
|
||||
}),
|
||||
resolve: me,
|
||||
resolve: me(slug),
|
||||
};
|
||||
|
||||
if (collection.config.auth.maxLoginAttempts > 0) {
|
||||
|
||||
Reference in New Issue
Block a user