Skip to content

Commit

Permalink
Only create password reset fields if needed (#4987)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Mar 3, 2021
1 parent 490d52c commit 098ce08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-bees-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/auth': major
---

The `passwordReset*` fields and `magicAuth*` fields are only added to the system if `passwordResetLink` and `magicAuthLink` respectively are set.
16 changes: 9 additions & 7 deletions packages-next/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ export function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({
listView: { fieldMode: 'hidden' },
},
} as const;

// These field names have to follow this format so that for e.g
// validateAuthToken() behaves correctly.
const tokenFields = (tokenType: 'passwordReset' | 'magicAuth') => ({
[`${tokenType}Token`]: password({ ...fieldConfig }),
[`${tokenType}IssuedAt`]: timestamp({ ...fieldConfig }),
[`${tokenType}RedeemedAt`]: timestamp({ ...fieldConfig }),
});
const additionalListFields = {
[`passwordResetToken`]: password({ ...fieldConfig }),
[`passwordResetIssuedAt`]: timestamp({ ...fieldConfig }),
[`passwordResetRedeemedAt`]: timestamp({ ...fieldConfig }),
[`magicAuthToken`]: password({ ...fieldConfig }),
[`magicAuthIssuedAt`]: timestamp({ ...fieldConfig }),
[`magicAuthRedeemedAt`]: timestamp({ ...fieldConfig }),
...(passwordResetLink && tokenFields('passwordReset')),
...(magicAuthLink && tokenFields('magicAuth')),
};

/**
Expand Down

1 comment on commit 098ce08

@vercel
Copy link

@vercel vercel bot commented on 098ce08 Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.