@@ -47,6 +47,48 @@ describe('auth handlers', () => {
4747 assertContains ( html , 'Invalid email or password' )
4848 } )
4949
50+ it ( 'flash error message is cleared after being displayed once' , async ( ) => {
51+ // POST invalid credentials to trigger flash message
52+ let response = await router . fetch ( 'https://remix.run/login' , {
53+ method : 'POST' ,
54+ body : new URLSearchParams ( {
55+ 56+ password : 'wrongpassword' ,
57+ } ) ,
58+ redirect : 'manual' ,
59+ } )
60+
61+ assert . equal ( response . status , 302 )
62+ assert . equal ( response . headers . get ( 'Location' ) , '/login' )
63+
64+ // Follow redirect to see the error message (first request)
65+ let sessionCookie = getSessionCookie ( response )
66+ let firstFollowUp = await router . fetch ( 'https://remix.run/login' , {
67+ headers : {
68+ Cookie : `session=${ sessionCookie } ` ,
69+ } ,
70+ } )
71+
72+ let firstHtml = await firstFollowUp . text ( )
73+ assertContains ( firstHtml , 'Invalid email or password' )
74+
75+ // Get updated session cookie (session should be updated to clear flash)
76+ let updatedSessionCookie = getSessionCookie ( firstFollowUp ) || sessionCookie
77+
78+ // Refresh the page (second request) - error should NOT be shown
79+ let secondFollowUp = await router . fetch ( 'https://remix.run/login' , {
80+ headers : {
81+ Cookie : `session=${ updatedSessionCookie } ` ,
82+ } ,
83+ } )
84+
85+ let secondHtml = await secondFollowUp . text ( )
86+ assert . ok (
87+ ! secondHtml . includes ( 'Invalid email or password' ) ,
88+ 'Expected flash error to be cleared after first display' ,
89+ )
90+ } )
91+
5092 it ( 'POST /register creates new user and sets session' , async ( ) => {
5193 let uniqueEmail = `newuser-${ Date . now ( ) } @example.com`
5294
0 commit comments