mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Refactor signInByMailCode
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2021 Jonas Lochmann
|
* Copyright (C) 2019 - 2023 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -109,7 +109,7 @@ export const signInByMailCode = async ({ mailLoginToken, receivedCode, database
|
|||||||
database: Database
|
database: Database
|
||||||
// no transaction here because this is directly called from an API endpoint
|
// no transaction here because this is directly called from an API endpoint
|
||||||
}): Promise<{ mailAuthToken: string }> => {
|
}): Promise<{ mailAuthToken: string }> => {
|
||||||
return database.transaction(async (transaction) => {
|
const result = await database.transaction(async (transaction) => {
|
||||||
const entry = await database.mailLoginToken.findOne({
|
const entry = await database.mailLoginToken.findOne({
|
||||||
where: {
|
where: {
|
||||||
mailLoginToken
|
mailLoginToken
|
||||||
@@ -127,9 +127,9 @@ export const signInByMailCode = async ({ mailLoginToken, receivedCode, database
|
|||||||
await entry.save({ transaction })
|
await entry.save({ transaction })
|
||||||
|
|
||||||
if (entry.remainingAttempts === 0) {
|
if (entry.remainingAttempts === 0) {
|
||||||
throw new Gone()
|
return () => { throw new Gone() }
|
||||||
} else {
|
} else {
|
||||||
throw new Forbidden()
|
return () => { throw new Forbidden() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +151,8 @@ export const signInByMailCode = async ({ mailLoginToken, receivedCode, database
|
|||||||
transaction
|
transaction
|
||||||
})
|
})
|
||||||
|
|
||||||
return { mailAuthToken }
|
return () => ({ mailAuthToken })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return result()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user