import fastifyStatic from '@fastify/static' import path from 'path' import uuid4 from 'uuid4' import postSchema from './../../schema/auth.js' /** * handle static files * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License * */ export default async function(fastify, opts) { /** * getting all users * * * @param {object} request * @param {object} response * */ fastify.post('/', { schema: postSchema }, async function(request, reply) { if (process.env.APP_AUTH_TOKEN === request.body.authToken) { const token = fastify.jwt.sign({ 'user': uuid4() }) return reply .setCookie('token', token, { //domain: 'your.domain', path: '/', //secure: true, // send cookie over HTTPS only httpOnly: true, sameSite: true // alternative CSRF protection }) .code(200) .send() } reply .code(403) .send() } ) }