sergiodxa / remix-auth

Simple Authentication for Remix
MIT License
1.94k stars 112 forks source link

Form Data can not be accessed when calling `authenticator.authenticate` #207

Closed fkrauthan closed 1 year ago

fkrauthan commented 1 year ago

Describe the bug

I am trying to implement some additional processing on top of authenticator.authenticate that requires me to access formData before calling authenticate. However, given that formData can only be read once it errors out during the authenticate call.

Your Example Website or App

NA

Steps to Reproduce the Bug or Issue

  1. Call await request.formData();
  2. Call await authenticator.authenticate('form-login', request, {});

Expected behavior

It works fine and logs me in (and/or allows me to pass in the already parsed formData)

Screenshots or Videos

No response

Platform

Additional context

No response

sergiodxa commented 1 year ago

You need to clone the request before calling authenticator.authenticate if you plan to read the FormData

let formData = await request.clone().formData()
await authenticator.authenticate('strategy', request, options);
fkrauthan commented 1 year ago

Ah cool, I will give that a try. Might be worth documenting as the error you get is not very obvious and especially in cases like password reset or activation this might be a sort of common use-case.