Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Created May 22, 2018 16:53
Show Gist options
  • Save gc-codesnippets/3fdca648c51d75e0137014962304a37e to your computer and use it in GitHub Desktop.
Save gc-codesnippets/3fdca648c51d75e0137014962304a37e to your computer and use it in GitHub Desktop.
async signup(parent, args, ctx, info) {
args.email = args.email.toLowerCase();
const password = await bcrypt.hash(args.password, 10);
const user = await ctx.db.mutation.createUser(
{
data: {
...args,
password,
permissions: { set: ['USER'] },
},
},
info
);
const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
ctx.response.cookie('token', token, {
maxAge: 1000 * 60 * 60 * 24 * 365,
httpOnly: true,
});
return user;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment