implement verify graphql resolver

This commit is contained in:
Elliot DeNolf
2020-09-24 16:39:38 -04:00
parent a412e68e89
commit 87ccdae795
4 changed files with 35 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
/* eslint-disable no-param-reassign */
function verifyEmail(collection) {
async function resolver(_, args, context) {
if (args.locale) context.req.locale = args.locale;
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale;
const options = {
collection,
token: args.token,
req: context.req,
res: context.res,
api: 'GraphQL',
};
const success = await this.operations.collections.auth.verifyEmail(options);
return success;
}
const verifyEmailResolver = resolver.bind(this);
return verifyEmailResolver;
}
module.exports = verifyEmail;

View File

@@ -20,6 +20,7 @@ async function verifyEmail(args) {
user._verified = true;
await user.save();
return true;
}
module.exports = verifyEmail;

View File

@@ -16,7 +16,7 @@ function registerCollections() {
} = this.graphQL.resolvers.collections;
const {
login, logout, me, init, refresh, forgotPassword, resetPassword,
login, logout, me, init, refresh, forgotPassword, resetPassword, verifyEmail,
} = this.graphQL.resolvers.collections.auth;
Object.keys(this.collections).forEach((slug) => {
@@ -266,6 +266,14 @@ function registerCollections() {
resolve: resetPassword(collection),
};
this.Mutation.fields[`verifyEmail${singularLabel}`] = {
type: GraphQLBoolean,
args: {
token: { type: GraphQLString },
},
resolve: verifyEmail(collection),
};
this.Mutation.fields[`refreshToken${singularLabel}`] = {
type: new GraphQLObjectType({
name: formatName(`${slug}Refreshed${singularLabel}`),

View File

@@ -6,7 +6,7 @@ const logout = require('../auth/graphql/resolvers/logout');
const me = require('../auth/graphql/resolvers/me');
const refresh = require('../auth/graphql/resolvers/refresh');
const resetPassword = require('../auth/graphql/resolvers/resetPassword');
// const verifyEmail = require('../auth/resolvers/verifyEmail');
const verifyEmail = require('../auth/graphql/resolvers/verifyEmail');
const create = require('../collections/graphql/resolvers/create');
const find = require('../collections/graphql/resolvers/find');
@@ -37,7 +37,7 @@ function bindResolvers(ctx) {
me: me.bind(ctx),
refresh: refresh.bind(ctx),
resetPassword: resetPassword.bind(ctx),
// verifyEmail: verifyEmail.bind(ctx),
verifyEmail: verifyEmail.bind(ctx),
},
},
globals: {