From 61c7bb28c2239012d772f4e8bb2fbf2a3213f876 Mon Sep 17 00:00:00 2001 From: keyan Date: Fri, 25 Aug 2023 14:22:02 -0500 Subject: [PATCH] allow name checking if you aren't logged in --- api/resolvers/user.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/api/resolvers/user.js b/api/resolvers/user.js index 9866653b..c8ff3b75 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -109,13 +109,11 @@ export default { users: async (parent, args, { models }) => await models.user.findMany(), nameAvailable: async (parent, { name }, { models, me }) => { - if (!me) { - throw new GraphQLError('you must be logged in', { extensions: { code: 'UNAUTHENTICATED' } }) + let user + if (me) { + user = await models.user.findUnique({ where: { id: me.id } }) } - - const user = await models.user.findUnique({ where: { id: me.id } }) - - return user.name?.toUpperCase() === name?.toUpperCase() || !(await models.user.findUnique({ where: { name } })) + return user?.name?.toUpperCase() === name?.toUpperCase() || !(await models.user.findUnique({ where: { name } })) }, topCowboys: async (parent, { cursor }, { models, me }) => { const decodedCursor = decodeCursor(cursor)