From bbae89d63326ead1007aea8a60abe3f81c5cde0c Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Wed, 16 Dec 2020 16:57:26 -0500 Subject: [PATCH] Minor code cleanup --- api/src/controllers/auth.ts | 4 ++-- api/src/services/users.ts | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/api/src/controllers/auth.ts b/api/src/controllers/auth.ts index c666b996d9..05313e577e 100644 --- a/api/src/controllers/auth.ts +++ b/api/src/controllers/auth.ts @@ -167,9 +167,9 @@ router.post( }; const service = new UsersService({ accountability, schema: req.schema }); - + try { - await service.requestPasswordReset(req.body.email, req.body.reset_url); + await service.requestPasswordReset(req.body.email, req.body.reset_url || null); } catch { // We don't want to give away what email addresses exist, so we'll always return a 200 // from this endpoint diff --git a/api/src/services/users.ts b/api/src/services/users.ts index 7cb64d6482..192caac1f3 100644 --- a/api/src/services/users.ts +++ b/api/src/services/users.ts @@ -115,15 +115,14 @@ export class UsersService extends ItemsService { } } - async requestPasswordReset(email: string, url: string) { + async requestPasswordReset(email: string, url: string | null) { const user = await this.knex.select('id').from('directus_users').where({ email }).first(); if (!user) throw new ForbiddenException(); const payload = { email, scope: 'password-reset' }; const token = jwt.sign(payload, env.SECRET as string, { expiresIn: '1d' }); - - let acceptURL = env.PUBLIC_URL + '/admin/reset-password?token=' + token - if(url && url !== '') acceptURL = url + '?token=' + token + + const acceptURL = url ? `${url}?token=${token}` : `${env.PUBLIC_URL}/admin/reset-password?token=${token}`; await sendPasswordResetMail(email, acceptURL); }