Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
0afa80345d | |||
dbb0d177b8
|
|||
4ffc06db7b | |||
588f3bae89
|
14
CHANGELOG.md
14
CHANGELOG.md
@@ -2,8 +2,22 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
|
||||
|
||||
#### [0.4.3](https://git.odit.services/kauft.es/linkylinky/compare/0.4.2...0.4.3)
|
||||
|
||||
- Fixed auth error crashing the entire server thanks to fastify handling stuff not the same way that they do in the docs..... [`#1`](https://git.odit.services/kauft.es/linkylinky/issues/1)
|
||||
|
||||
#### [0.4.2](https://git.odit.services/kauft.es/linkylinky/compare/0.4.1...0.4.2)
|
||||
|
||||
> 18 August 2021
|
||||
|
||||
- Changed register api route and added user deletion route [`588f3ba`](https://git.odit.services/kauft.es/linkylinky/commit/588f3bae8980f76461d20e15475ec797078b0b54)
|
||||
- 🚀RELEASE 0.4.2 [`4ffc06d`](https://git.odit.services/kauft.es/linkylinky/commit/4ffc06db7bb84bc7bfc9c57a80927f7201185274)
|
||||
|
||||
#### [0.4.1](https://git.odit.services/kauft.es/linkylinky/compare/0.4.0...0.4.1)
|
||||
|
||||
> 18 August 2021
|
||||
|
||||
- 🚀RELEASE 0.4.1 [`d889432`](https://git.odit.services/kauft.es/linkylinky/commit/d889432ce8a403f6a609423eaf458a5904dc5b98)
|
||||
- Fixed jwtcount not being recognized [`44830f0`](https://git.odit.services/kauft.es/linkylinky/commit/44830f08bc212f8079b5ac2da3d51eedbe6d5c41)
|
||||
|
||||
#### [0.4.0](https://git.odit.services/kauft.es/linkylinky/compare/0.3.0...0.4.0)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@odit/shortener-backend",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.3",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
|
@@ -45,25 +45,31 @@ fastify.decorate('verifyJWT', function async(request, reply, done) {
|
||||
|
||||
fastify.jwt.verify(token, async (err, decoded) => {
|
||||
if (err) {
|
||||
fastify.log.error(err)
|
||||
done(new Error("JWT Validation failed"))
|
||||
fastify.log.error("JWT validation failed:")
|
||||
done(new Error("JWT Validation failed"));
|
||||
}
|
||||
fastify.log.info(`Token verified. User is ${decoded.payload.user}`);
|
||||
request.user = decoded.payload.user;
|
||||
else {
|
||||
if (!decoded.payload) {
|
||||
done(new Error("JWT is empty"));
|
||||
}
|
||||
fastify.log.info(`Token verified. User is ${decoded.payload.user}`);
|
||||
|
||||
const jwtcount = (await knex.select('jwtcount')
|
||||
.from('users')
|
||||
.where('username', '=', decoded.payload.user)
|
||||
.limit(1))[0].jwtcount;
|
||||
const jwtcount = (await knex.select('jwtcount')
|
||||
.from('users')
|
||||
.where('username', '=', decoded.payload.user)
|
||||
.limit(1))[0].jwtcount;
|
||||
|
||||
if (decoded.payload.jwtcount < jwtcount) {
|
||||
fastify.log.error("Auth ended at jwtcount")
|
||||
done(new Error("JWT in no longer valid"))
|
||||
if (decoded.payload.jwtcount < jwtcount) {
|
||||
fastify.log.error("Auth ended at jwtcount")
|
||||
done(new Error("JWT in no longer valid"))
|
||||
}
|
||||
else {
|
||||
fastify.log.info(`JWT count verified`);
|
||||
request.user = decoded.payload.user;
|
||||
done()
|
||||
}
|
||||
}
|
||||
fastify.log.info(`JWT count verified`);
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
//Automagic Amazn redirects on /a/
|
||||
@@ -223,7 +229,7 @@ fastify.get('/api/:shortcode', async (req, res) => {
|
||||
|
||||
|
||||
//User registration
|
||||
fastify.post('/api/register', async (req, res) => {
|
||||
fastify.post('/api/auth/register', async (req, res) => {
|
||||
if (!config.registrationEnabled) {
|
||||
res.statusCode = 400;
|
||||
return "Registration was disabled by your admin";
|
||||
@@ -347,6 +353,14 @@ fastify.after(() => {
|
||||
return "Done!";
|
||||
});
|
||||
|
||||
fastify.post('/api/auth/deleteme', { onRequest: fastify.auth([fastify.basicAuth, fastify.verifyJWT]) }, async (req, reply) => {
|
||||
await knex('users')
|
||||
.where('username', '=', req.user)
|
||||
.delete();
|
||||
|
||||
return "Done!";
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user