Created
May 22, 2018 16:53
-
-
Save gc-codesnippets/3fdca648c51d75e0137014962304a37e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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