How to access form data from before a user is authenticated?
So basically, I have a user fill out a form that is then stored in global state. Once they complete the form, they are instructed to login with google to 'complete' their account. I'd like to link this form data to their account somehow but I'm struggling with finding a way to pass this data through the actual authentication process.
Has anyone ran into something similar and how did they get around it? Do I need to store the form data in a cookie or some sort of persisted state, or is there a way to pass data to the middleware and handle it there?
5 Replies
Also just had the idea of passing an identifier through the redirect url. Thoughts?
My app just has them authenticate with Google first. Then they fill out the form. If you’re using an auth provider that uses a pop up you don’t lose any state. If you’re auth provider works via redirection you will need to save the partially complete user data in your database and then ‘finish’ it later
If they never complete the sign up you can have a cleanup job that runs every once in a while to clean up these entries
@tcaputi how would I reference the partially completed data post login? I’d need some sort of identifier that can persist through the login.
I don't know nextauth very well but as a general idea, you could try putting it into local storage before opening the Auth route and then checking for that local storage on the callback route. And if it's there send it to the server then
Local storage works and is probably the best idea. My app uses firebase auth which has a concept of anonymous users that can be upgraded later. I’m not using that right now though. But like I said I just do it in reverse so they log in with Google first and then finish the form after. This way I always have a user ID to work with