roschaefer 62c8d34079 Fix expiration dates of JWT and cookie
This won't fix the bug that can happen in `nuxtServerInit`. However,
according to the docs, we accepted JWT which was valid for 1000 days and
our cookie was valid for 3 days - completely weird.

See:
https://github.com/auth0/node-jsonwebtoken
https://github.com/nuxt-community/apollo-module
2019-08-22 22:29:50 +02:00

17 lines
476 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 token = jwt.sign(user, CONFIG.JWT_SECRET, {
expiresIn: '1d',
issuer: CONFIG.GRAPHQL_URI,
audience: CONFIG.CLIENT_URI,
subject: user.id.toString(),
})
// jwt.verifySignature(token, CONFIG.JWT_SECRET, (err, data) => {
// console.log('token verification:', err, data)
// })
return token
}