File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -263,10 +263,23 @@ export const auth = betterAuth({
263263 } ,
264264 hooks : {
265265 after : createAuthMiddleware ( async ( ctx ) => {
266- if ( ctx . path === "/verify-email" || ctx . path === "/sign-in/social" ) {
266+ if (
267+ ctx . path === "/magic-link/verify" ||
268+ ctx . path === "/verify-email" ||
269+ ctx . path === "/sign-in/social"
270+ ) {
267271 // After verifying email, send them a welcome email
268272 const newSession = ctx . context . newSession ;
269273 if ( newSession ) {
274+ const oneMinuteAgo = new Date ( Date . now ( ) - 60 * 1000 ) ;
275+ if (
276+ ctx . path === "/magic-link/verify" &&
277+ newSession . user . createdAt < oneMinuteAgo
278+ ) {
279+ // magic link is for an account that was created more than a minute ago, so just a normal sign in
280+ // no need to send welcome email
281+ return false ;
282+ }
270283 await sendEmail ( {
271284 to : newSession . user . email ,
272285 template : "welcome" ,
You can’t perform that action at this time.
0 commit comments