Skip to content

Instantly share code, notes, and snippets.

@timsuchanek
Created May 22, 2018 17:04
Show Gist options
  • Save timsuchanek/214302966a5d41463dd363e551f18aa0 to your computer and use it in GitHub Desktop.
Save timsuchanek/214302966a5d41463dd363e551f18aa0 to your computer and use it in GitHub Desktop.
import { addFragmentToInfo } from 'graphql-binding'
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'] },
},
},
addFragmentToInfo(info, `fragment UserWithId on User { id }`)
);
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