File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { createAuthClient } from 'better-auth/react'
2+ import { magicLinkClient } from 'better-auth/client/plugins'
3+
4+ export const authClient = createAuthClient ( {
5+ plugins : [
6+ magicLinkClient ( )
7+ ]
8+ } )
29
3- export const authClient = createAuthClient ( )
Original file line number Diff line number Diff line change 11import { betterAuth } from 'better-auth'
2+ import { magicLink } from 'better-auth/plugins'
23import { tanstackStartCookies } from 'better-auth/tanstack-start'
34
45export const auth = betterAuth ( {
6+ secret : process . env . BETTER_AUTH_SECRET || "dev-secret-key-at-least-32-chars-long-exemplai" ,
57 emailAndPassword : {
68 enabled : true ,
79 } ,
8- plugins : [ tanstackStartCookies ( ) ] ,
10+ plugins : [
11+ tanstackStartCookies ( ) ,
12+ magicLink ( {
13+ sendMagicLink : async ( { email, url } ) => {
14+ console . log ( `\n==================================================` )
15+ console . log ( `[Dev Mailer] Magic Link for: ${ email } ` )
16+ console . log ( `URL: ${ url } ` )
17+ console . log ( `==================================================\n` )
18+ } ,
19+ } ) ,
20+ ] ,
921} )
22+
Original file line number Diff line number Diff line change @@ -56,27 +56,15 @@ function AuthPage() {
5656 // Log magic link request to the terminal/console
5757 console . log ( `[Auth] Magic Link Sign In initiated for email: "${ value . email } "` ) ;
5858
59- if (
60- authClient . signIn &&
61- "magicLink" in authClient . signIn &&
62- typeof ( authClient . signIn as any ) . magicLink === "function"
63- ) {
64- const { error } = await ( authClient . signIn as any ) . magicLink ( {
65- email : value . email ,
66- callbackURL : "/" ,
67- } ) ;
68- if ( error ) {
69- setGlobalError ( error . message || "Failed to send magic link" ) ;
70- } else {
71- setSuccessMessage ( "Magic link sent! Please check your email inbox." ) ;
72- }
59+ const { error } = await authClient . signIn . magicLink ( {
60+ email : value . email ,
61+ callbackURL : "/" ,
62+ } ) ;
63+ if ( error ) {
64+ setGlobalError ( error . message || "Failed to send magic link" ) ;
7365 } else {
74- // Log warning & simulate success response to developer/terminal
75- console . warn (
76- "[Auth] better-auth magicLink plugin is not configured. Simulating success."
77- ) ;
7866 setSuccessMessage (
79- ` Magic link has been simulated & logged to terminal! (Email: ${ value . email } )`
67+ " Magic link sent! Please check your email inbox."
8068 ) ;
8169 }
8270 } else {
@@ -369,6 +357,7 @@ function AuthPage() {
369357 </ form . Subscribe >
370358 </ form >
371359 </ AuthCard >
360+
372361 </ div >
373362 ) ;
374363}
You can’t perform that action at this time.
0 commit comments