fix: me auth route breaks with query params (#648)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -299,7 +299,7 @@ function initCollectionsGraphQL(payload: Payload): void {
|
||||
},
|
||||
},
|
||||
}),
|
||||
resolve: me(slug),
|
||||
resolve: me(collection),
|
||||
};
|
||||
|
||||
if (collection.config.auth.maxLoginAttempts > 0) {
|
||||
|
||||
Reference in New Issue
Block a user