From d28b274fe3a2635c1546dff112454c723a646ad2 Mon Sep 17 00:00:00 2001 From: Francis Li Date: Thu, 28 Mar 2024 16:40:03 -0700 Subject: [PATCH] Lint changes --- server/helpers/license/verifyLicense.js | 2 -- server/plugins/auth/auth.js | 7 +++-- server/routes/api/v1/auth/local.js | 40 ++++++++++++------------- server/routes/api/v1/licenses/index.js | 2 -- server/routes/api/v1/users/index.js | 2 -- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/server/helpers/license/verifyLicense.js b/server/helpers/license/verifyLicense.js index 9944e0ed..457096c3 100644 --- a/server/helpers/license/verifyLicense.js +++ b/server/helpers/license/verifyLicense.js @@ -1,5 +1,3 @@ -'use strict'; - import fetchLicenseVerificationForm from './fetchLicenseVerificationForm.js'; import fetchLicenseVerificationResults from './fetchLicenseVerificationResults.js'; import { diff --git a/server/plugins/auth/auth.js b/server/plugins/auth/auth.js index 336abbf4..195cb647 100644 --- a/server/plugins/auth/auth.js +++ b/server/plugins/auth/auth.js @@ -1,17 +1,18 @@ import fp from 'fastify-plugin'; import fastifyAuth from '@fastify/auth'; +import bcrypt from 'bcrypt'; // the use of fastify-plugin is required to be able // to export the decorators to the outer scope -export default fp(async function (fastify, opts) { +export default fp(async function (fastify, _opts) { fastify - .decorate('verifyAdmin', function (request, reply, done) { + .decorate('verifyAdmin', function (_request, _reply, done) { // your validation logic done(); // pass an error if the authentication fails }) // Local strategy to authenticate users with username and password - .decorate('localStrategy', async (request, reply, done) => { + .decorate('localStrategy', async (request, _reply, done) => { try { //findUniqueOrThrow is a method provided by Prisma to return a single record or an error if none found const user = fastify.prisma.users.findUniqueOrThrow({ diff --git a/server/routes/api/v1/auth/local.js b/server/routes/api/v1/auth/local.js index 7189b374..be089c9d 100644 --- a/server/routes/api/v1/auth/local.js +++ b/server/routes/api/v1/auth/local.js @@ -1,52 +1,50 @@ -'use strict'; - import bcrypt from 'bcrypt'; // could be reimplamented with fastify-passport -export default async function (fastify, opts) { +export default async function (fastify, _opts) { // add a login route that returns a login page - fastify.get('/login', (req, res) => { + fastify.get('/login', (_request, reply) => { // currently only redirects to login page - res.redirect('/login'); + reply.redirect('/login'); }); // add a login route that handles the actual login - fastify.post('/login', async (req, res) => { - const { email, password } = req.body; + fastify.post('/login', async (request, reply) => { + const { email, password } = request.body; try { const user = await fastify.prisma.user.findUnique({ email }); if (!user) { - res.status(401); - res.send('No user with that email'); + reply.status(401); + reply.send('No user with that email'); return; } const result = await bcrypt.compare(password, user.password); if (!result) { - res.status(401); - res.send('Invalid password'); + reply.status(401); + reply.send('Invalid password'); return; } - return (req.session.authenticated = true); + return (request.session.authenticated = true); } catch (error) { - res.status(500); - res.send('Internal Server Error'); + reply.status(500); + reply.send('Internal Server Error'); } }); // add a logout route - fastify.get('/logout', (req, res) => { - if (req.session.authenticated) { - req.session.destroy((err) => { + fastify.get('/logout', (request, reply) => { + if (request.session.authenticated) { + request.session.destroy((err) => { if (err) { - res.status(500); - res.send('Internal Server Error'); + reply.status(500); + reply.send('Internal Server Error'); } else { - res.redirect('/'); + reply.redirect('/'); } }); } else { - res.redirect('/'); + reply.redirect('/'); } }); } diff --git a/server/routes/api/v1/licenses/index.js b/server/routes/api/v1/licenses/index.js index 0a2a2a20..02b8624b 100644 --- a/server/routes/api/v1/licenses/index.js +++ b/server/routes/api/v1/licenses/index.js @@ -1,5 +1,3 @@ -'use strict'; - import verifyLicense from '../../../../helpers/license/verifyLicense.js'; export default async function (fastify) { diff --git a/server/routes/api/v1/users/index.js b/server/routes/api/v1/users/index.js index e88c0d14..e126400c 100644 --- a/server/routes/api/v1/users/index.js +++ b/server/routes/api/v1/users/index.js @@ -1,5 +1,3 @@ -'use strict'; - import crypto from 'crypto'; import bcrypt from 'bcrypt';