Skip to content
Snippets Groups Projects
Unverified Commit 8cbf08ac authored by Thomas SAUVAGE's avatar Thomas SAUVAGE
Browse files

Better cron

parent 22f5d852
No related branches found
No related tags found
1 merge request!4Trying to implement openid
import AuthCodeVerifier from 'App/Models/AuthCodeVerifier' import AuthCodeVerifier from 'App/Models/AuthCodeVerifier'
// TODO: Fix this const sqlRequest = "created_at > current_date - interval '1' hour"
export const cronRemoveOldCodeVerifiers = async () => {
console.log('Before:', await AuthCodeVerifier.all()) /** Remove old code verifiers from the database `AuthCodeVerifier`
await AuthCodeVerifier.query().delete().whereRaw("created_at < current_date - interval '1' hour") * Code verifiers must be stored between the moment:
console.log('After:', await AuthCodeVerifier.all()) * - the user ask for a login to `auth.binets.fr`: codeVerifier is created
* - the user as entered his login: codeVerifier is deleted
*
* => If the user never enter his login, codeVerifier is never deleted.
* Therefor we need to execute this cron regularly
* */
export const cronRemoveOldCodeVerifiers = async ({ response }) => {
const willBeDeleted = await AuthCodeVerifier.query().whereRaw(sqlRequest)
await AuthCodeVerifier.query().delete().whereRaw(sqlRequest)
return response.ok({
message: 'Old code verifiers successfully deleted',
deletedCodeVerifiersCreatedAt: willBeDeleted.map(({ createdAt }) => createdAt.toString()),
})
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment