🚸 Improve magic link sign in experience

New email and sign in feedback
This commit is contained in:
Baptiste Arnaud
2023-03-13 11:20:28 +01:00
parent 4ae9ea32e4
commit 48db171c1b
7 changed files with 129 additions and 37 deletions

View File

@@ -13,6 +13,7 @@ import { User } from 'db'
import { env, getAtPath, isDefined, isNotEmpty } from 'utils'
import { mockedUser } from '@/features/auth'
import { getNewUserInvitations } from '@/features/auth/api'
import { sendVerificationRequest } from './sendVerificationRequest'
const providers: Provider[] = []
@@ -42,6 +43,7 @@ if (isNotEmpty(env('SMTP_FROM')) && process.env.SMTP_AUTH_DISABLED !== 'true')
},
},
from: env('SMTP_FROM'),
sendVerificationRequest,
})
)

View File

@@ -0,0 +1,16 @@
import { EmailConfig } from 'next-auth/providers/email'
import { sendMagicLinkEmail } from 'emails'
type Props = {
identifier: string
url: string
provider: Partial<Omit<EmailConfig, 'options'>>
}
export const sendVerificationRequest = async ({ identifier, url }: Props) => {
try {
await sendMagicLinkEmail({ url, to: identifier })
} catch (err) {
throw new Error(`Email(s) could not be sent`)
}
}