Skip to content

Commit

Permalink
add more descriptive errors for login link issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Sep 10, 2024
1 parent 280b651 commit 04f5d91
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/utils/prisma.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,26 @@ async function validateMagicLink(link: string, sessionMagicLink?: string) {
validateSessionMagicLink = payload.validateSessionMagicLink
} catch (error: unknown) {
console.error(error)
throw new Error('Sign in link invalid. Please request a new one.')
throw new Error(
'Sign in link invalid (link payload is invalid). Please request a new one.',
)
}

if (typeof emailAddress !== 'string') {
console.error(`Email is not a string. Maybe wasn't set in the session?`)
throw new Error('Sign in link invalid. Please request a new one.')
throw new Error(
'Sign in link invalid (email is not a string). Please request a new one.',
)
}

if (validateSessionMagicLink) {
if (!sessionLinkCode) {
console.error(
'Must validate session magic link but no session link provided',
)
throw new Error('Sign in link invalid. Please request a new one.')
throw new Error(
'Sign in link invalid (no link validation cookie found). Please request a new link.',
)
}
if (linkCode !== sessionLinkCode) {
console.error(`Magic link does not match sessionMagicLink`)
Expand All @@ -123,7 +129,9 @@ async function validateMagicLink(link: string, sessionMagicLink?: string) {

if (typeof linkCreationDateString !== 'string') {
console.error('Link expiration is not a string.')
throw new Error('Sign in link invalid. Please request a new one.')
throw new Error(
'Sign in link invalid (link expiration is not a string). Please request a new one.',
)
}

const linkCreationDate = new Date(linkCreationDateString)
Expand Down

0 comments on commit 04f5d91

Please sign in to comment.