Skip to content

Commit

Permalink
Lint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
francisli committed Mar 28, 2024
1 parent 5b7563e commit d28b274
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
2 changes: 0 additions & 2 deletions server/helpers/license/verifyLicense.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import fetchLicenseVerificationForm from './fetchLicenseVerificationForm.js';
import fetchLicenseVerificationResults from './fetchLicenseVerificationResults.js';
import {
Expand Down
7 changes: 4 additions & 3 deletions server/plugins/auth/auth.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
40 changes: 19 additions & 21 deletions server/routes/api/v1/auth/local.js
Original file line number Diff line number Diff line change
@@ -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('/');
}
});
}
2 changes: 0 additions & 2 deletions server/routes/api/v1/licenses/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import verifyLicense from '../../../../helpers/license/verifyLicense.js';

export default async function (fastify) {
Expand Down
2 changes: 0 additions & 2 deletions server/routes/api/v1/users/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import crypto from 'crypto';
import bcrypt from 'bcrypt';

Expand Down

0 comments on commit d28b274

Please sign in to comment.