Created
May 22, 2018 17:04
-
-
Save timsuchanek/214302966a5d41463dd363e551f18aa0 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
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