ory / kratos-selfservice-ui-react-nextjs

A full reference implementation for designing your own login, registration, recovery, verification, ... pages using Ory Kratos' APIs.
https://www.ory.sh/
Apache License 2.0
135 stars 56 forks source link

Proposal: Flows refactor #32

Closed lstellway closed 2 years ago

lstellway commented 2 years ago

Description

While following this NextJS example and implementing my own frontend, I saw the same pattern was used for all of the user flows (get or initialize the flow based on the router query).

I thought it could be nice to abstract it outside of the view into a helper - let me know what you think!

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
kratos-reference-ui-react-nextjs ✅ Ready (Inspect) Visit Preview May 5, 2022 at 7:17PM (UTC)
aeneasr commented 2 years ago

Thank you! I think from a code perspective this is really good! I think though that we want to keep it verbose because the app is intended to have a learning effect on readers. I think it is best if the code is very clear and visible without being spread across files, to give the reader an easy time navigating it. I think moving the shared logic into a file could make this a bit more difficult to understand. What do you think?

lstellway commented 2 years ago

Apoligies for the delay (I've been out of town).

The structure I proposed comes from what I am accustom to: the "fat model, skinny controller" approach from the MVC design pattern. Also was trying to get rid of some repetitive logic, specifically with error handling (thinking about "DRY" / "don't repeat yourself").

I suppose it does make sense to keep things verbose and in context for the sake of learning. Everybody is different, but I found it easier to understand with the bulk of the logic in one place.

Thanks for the time / consideration!

aeneasr commented 2 years ago

No problem! I absolutely agree, DRY code is better, your solution is too. We use the code in a couple of places though (eg docs) and its very useful to have all the logic in that file. But again, in a real app, this should be cleaned up!