Skip to content

Instantly share code, notes, and snippets.

@satyapendem
Created December 20, 2019 06:42
Show Gist options
  • Save satyapendem/daba7c58c7185b72c07ed133f4cb32d6 to your computer and use it in GitHub Desktop.
Save satyapendem/daba7c58c7185b72c07ed133f4cb32d6 to your computer and use it in GitHub Desktop.
async function authRouter(fastify, opts) {
fastify.post('/api/v1/generateAccessToken', async (request, reply) => {
const { email, username, userId } = request.body;
if (!email || !username || !userId) {
reply.status(400).send({ error: true, msg: 'Mandatory fields are missing' });
}
//SET DB level checks if any
const token = fastify.jwt.sign({ email, username, userId }, { expiresIn: 86400 });
reply.send({ token, email, userId });
});
}
module.exports = authRouter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment