eidellev / inertiajs-adonisjs

280 stars 17 forks source link

Login Flash messages not working with Exception redirect #130

Open akatora28 opened 10 months ago

akatora28 commented 10 months ago

I was following the instructions to setup error handling for invalid login attempts with adonis, i.e. catching the default 400 error response. It seems that flash messages aren't persisted on redirects from the error handler.

Below is the code from the documentation

//app/Exceptions/Hander.ts
    if (['E_INVALID_AUTH_PASSWORD', 'E_INVALID_AUTH_UID'].includes(error.code)) {
      session.flash('errors', { login: error.message });
      return response.redirect('/login');
    }

Changing the redirect to use response.redirect().back() fixed the issue and displayed flash messages after redirect

//app/Exceptions/Hander.ts
    if (['E_INVALID_AUTH_PASSWORD', 'E_INVALID_AUTH_UID'].includes(error.code)) {
      session.flash('errors', { login: error.message });
      return response.redirect().back();
    }