roschaefer e41a639cf1 fix(jwt): Encode only 3 attributes in JWT
This will prevent unintentional encoding of users email addresses in the
JWT.

@steffi201028 this might be interesting for you as well.
2020-02-18 11:23:04 +01:00

15 lines
395 B
JavaScript

import jwt from 'jsonwebtoken'
import CONFIG from './../config'
// Generate an Access Token for the given User ID
export default function encode(user) {
const { id, name, slug } = user
const token = jwt.sign({ id, name, slug }, CONFIG.JWT_SECRET, {
expiresIn: '1d',
issuer: CONFIG.GRAPHQL_URI,
audience: CONFIG.CLIENT_URI,
subject: user.id.toString(),
})
return token
}