Compare commits

..

No commits in common. "2518ced0fab78945fe29a4a136551b046f203e51" and "11943b667c322dc4017b5d9e77bcf2669ff62e30" have entirely different histories.

View file

@ -10,7 +10,7 @@ module.exports = ({ services: { sortRolesByLevel, signJwt } }) => {
const { claimsNamespace, jwtExpirationInHours } = config const { claimsNamespace, jwtExpirationInHours } = config
function validateAuthToken(authTokenJwt) { async function validateAuthToken(authTokenJwt) {
try { try {
const { authToken } = jwtDecode(authTokenJwt) const { authToken } = jwtDecode(authTokenJwt)
return authToken return authToken
@ -28,22 +28,22 @@ module.exports = ({ services: { sortRolesByLevel, signJwt } }) => {
let deviceId let deviceId
let roles let roles
const [row] = await sql` try {
SELECT const [row] = await sql`
"user_id" as "userId", SELECT
"device_id" as "deviceId" "user_id" as "userId",
FROM "device_id" as "deviceId"
"auth_token" FROM
WHERE "auth_token"
"auth_token" = ${authToken} WHERE
` "auth_token" = ${authToken}
if (!row) { `
userId = row.userId
deviceId = row.deviceId
} catch (e) {
throw httpError(410, "Auth token not found") throw httpError(410, "Auth token not found")
} }
userId = row.userId
deviceId = row.deviceId
if (!userId) { if (!userId) {
await sql.begin(async (sql) => { await sql.begin(async (sql) => {
await sql`set constraints all deferred` await sql`set constraints all deferred`