Compare commits
2 commits
11943b667c
...
2518ced0fa
Author | SHA1 | Date | |
---|---|---|---|
2518ced0fa | |||
391fd6d380 |
1 changed files with 14 additions and 14 deletions
|
@ -10,7 +10,7 @@ module.exports = ({ services: { sortRolesByLevel, signJwt } }) => {
|
|||
|
||||
const { claimsNamespace, jwtExpirationInHours } = config
|
||||
|
||||
async function validateAuthToken(authTokenJwt) {
|
||||
function validateAuthToken(authTokenJwt) {
|
||||
try {
|
||||
const { authToken } = jwtDecode(authTokenJwt)
|
||||
return authToken
|
||||
|
@ -28,22 +28,22 @@ module.exports = ({ services: { sortRolesByLevel, signJwt } }) => {
|
|||
let deviceId
|
||||
let roles
|
||||
|
||||
try {
|
||||
const [row] = await sql`
|
||||
SELECT
|
||||
"user_id" as "userId",
|
||||
"device_id" as "deviceId"
|
||||
FROM
|
||||
"auth_token"
|
||||
WHERE
|
||||
"auth_token" = ${authToken}
|
||||
`
|
||||
userId = row.userId
|
||||
deviceId = row.deviceId
|
||||
} catch (e) {
|
||||
const [row] = await sql`
|
||||
SELECT
|
||||
"user_id" as "userId",
|
||||
"device_id" as "deviceId"
|
||||
FROM
|
||||
"auth_token"
|
||||
WHERE
|
||||
"auth_token" = ${authToken}
|
||||
`
|
||||
if (!row) {
|
||||
throw httpError(410, "Auth token not found")
|
||||
}
|
||||
|
||||
userId = row.userId
|
||||
deviceId = row.deviceId
|
||||
|
||||
if (!userId) {
|
||||
await sql.begin(async (sql) => {
|
||||
await sql`set constraints all deferred`
|
||||
|
|
Loading…
Add table
Reference in a new issue