fix: me auth route breaks with query params (#648)

This commit is contained in:
Dan Ribbens
2022-06-13 11:49:04 -04:00
committed by GitHub
parent 7083225abd
commit a1fe17d05d
5 changed files with 10 additions and 12 deletions

View File

@@ -1,10 +1,11 @@
import me from '../../operations/me';
import { Collection } from '../../../collections/config/types';
function meResolver(collectionSlug: string): any {
function meResolver(collection: Collection): any {
async function resolver(_, args, context) {
const options = {
collection,
req: context.req,
collectionSlug,
};
return me(options);
}

View File

@@ -2,6 +2,7 @@ import jwt from 'jsonwebtoken';
import { PayloadRequest } from '../../express/types';
import getExtractJWT from '../getExtractJWT';
import { User } from '../types';
import { Collection } from '../../collections/config/types';
export type Result = {
user?: User,
@@ -11,20 +12,20 @@ export type Result = {
}
export type Arguments = {
req: PayloadRequest,
collectionSlug: string
req: PayloadRequest
collection: Collection
}
async function me({
req,
collectionSlug,
collection,
}: Arguments): Promise<Result> {
const extractJWT = getExtractJWT(req.payload.config);
if (req.user) {
const user = { ...req.user };
if (user.collection !== collectionSlug) {
if (user.collection !== collection.config.slug) {
return {
user: null,
};

View File

@@ -5,7 +5,6 @@ import logout from '../operations/logout';
export default async function logoutHandler(req: PayloadRequest, res: Response, next: NextFunction): Promise<Response<{ message: string}> | void> {
try {
debugger;
const message = await logout({
collection: req.collection,
res,

View File

@@ -4,12 +4,9 @@ import me from '../operations/me';
export default async function meHandler(req: PayloadRequest, res: Response, next: NextFunction): Promise<any> {
try {
const collectionSlugMatch = req.originalUrl.match(/\/([^/]+)\/me\/?$/);
const [, collectionSlug] = collectionSlugMatch;
const response = await me({
req,
collectionSlug,
collection: req.collection,
});
return res.status(200).json(response);
} catch (err) {

View File

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