You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

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()
}
)
}