Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
6 changes: 3 additions & 3 deletions handlers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const jwt = require('jsonwebtoken')
const jose = require('jose')
const { totp } = require('otplib')
const { v4: uuidv4 } = require('uuid')

Expand Down Expand Up @@ -648,7 +648,7 @@ module.exports.login = async ({ query }) => {
if (!isValid) {
return respondError(new HTTPError('Invalid OTP', 403))
}
const token = jwt.sign({ email, jwt_uuid }, TOKEN_SECRET)
const token = await new jose.SignJWT({ email, jwt_uuid }).sign(TOKEN_SECRET)
return respondJSON({ payload: { jwt: token } })
}

Expand All @@ -663,7 +663,7 @@ module.exports.getToken = async ({ query }) => {
// return respondError(new HTTPError(`${user} not found`, 404))
// }

const token = jwt.sign({ email, jwt_uuid }, TOKEN_SECRET)
const token = await new jose.SignJWT({ email, jwt_uuid }).sign(TOKEN_SECRET)

try {
await fetch('https://api.sendgrid.com/v3/mail/send', {
Expand Down
5 changes: 3 additions & 2 deletions modules/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const jwt = require('jsonwebtoken')
const jose = require('jose')

const { HTTPError, respondError } = require('./utils')
const { getKVUser } = require('./users')
Expand All @@ -12,7 +12,8 @@ const verifyJWT = (headers) => {
}
let access = {}
try {
access = jwt.verify(token, TOKEN_SECRET)
const { payload } = jose.jwtVerify(token, TOKEN_SECRET)
access = payload
} catch (_) {
throw new HTTPError('Invalid portunus-jwt', 403)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/db.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { Deta } = require('deta-worker')
const { Deta } = require('../vendor/deta-worker')

module.exports = Deta(DETA_KEY)
6 changes: 4 additions & 2 deletions modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ module.exports.HTTPError = class extends Error {
}
}

module.exports.respondError = (err) =>
new Response(JSON.stringify({ message: err.message }), {
module.exports.respondError = (err) => {
console.error(err)
return new Response(JSON.stringify({ message: err.message }), {
headers: { ...this.corsHeaders, 'content-type': 'application/json' },
status: err.status || 500,
})
}

module.exports.respondJSON = ({ payload, status = 200, headers = {} }) =>
new Response(JSON.stringify(payload), {
Expand Down
Loading