Approaches to server side form validation - toddle x Supabase

  • tomthebigtree-1319304562217193563

    Tom Ireland

    3 months ago

    Hey, folks. Has anyone got any tips/tricks on how best to handle form validation server side when using toddle x Supabase?

    Is the answer to use Supabase Edge functions or CloudFlare Workers for this?

    Table constraints and RLS policy checks will only get you so far and I'm conscious of ensuring forms are properly validated, while reducing as much repetition fron end and server-side as possible.
  • lucasg-1319305044876591154

    Lucas G

    3 months ago

    Forms are typically validated on frontend upon submission. What are you trying to check for on the backend?
  • tomthebigtree-1319305705533997077

    Tom Ireland

    3 months ago

    Well, front end is for UX but need to ensure server-side is done as well. For example, I could make a post request from Postman and bypass the front end potentially introducing bad data, so need to handle potential situations where bad data might sneak through as front end validation is not solely reliable.
  • lucasg-1319306844015038587

    Lucas G

    3 months ago

    Ah are you looking to protect a sign-up form then
  • tomthebigtree-1319307059497402450

    Tom Ireland

    3 months ago

    Aye, well that and profile stuff.
  • Plus thinking about future improvements.
  • Where other forms will be required.
  • lucasg-1319307217790308393

    Lucas G

    3 months ago

    Profile stuff shouldn't be an issue as that should already be an authenticated call
  • The only one you can't really authenticate as easily would be a sign-up form or rather public forms in general
  • lucasg-1319307702094270464

    Lucas G

    3 months ago

    In which case, yeah, you'd need something in between to validate them. Stuff like request origin validation, rate limiting, etc
  • lucasg-1319308208841560126

    Lucas G

    3 months ago

    There's no one thing, it's about stacking checks
  • Sometimes people also save those type of forms to a temporary DB from which they clean/validate then pass to the main DB
  • tomthebigtree-1319308443189903452

    Tom Ireland

    3 months ago

    Aye. The use-case I have (and maybe it needs improved) is the profile. On signup, I create a record in the profile table with the user's auth id and email generated on signup. In order to create the record using a trigger function, other fields like first name, last name, etc., need to be null in order for the insert to work (there may be a way to improve that).

    The idea being fast signup without creating your profile completely immmediately. However, in order for your profile to be public, it needs to be complete. I can implement front end validation to ensure everything is checked before posting but that doesn't mean someone could get around it by hacking the developer tools or something.
  • tomthebigtree-1319308750900826125

    Tom Ireland

    3 months ago

    Given there is no null constraint on the table, you could still potentially have an incomplete profile if you hack around it.
  • Or I implement something that allows it without noticing.
  • lucasg-1319308834434580501

    Lucas G

    3 months ago

    Can you put the profile entry behind the sign-up, after an account activation step
  • tomthebigtree-1319309081097404508

    Tom Ireland

    3 months ago

    That's kinda what I'm doing but the insert from auth into profile needs other fields to either be present or accept a null value.
  • tomthebigtree-1319309548976341054

    Tom Ireland

    3 months ago

    So I opted for null as not an immediate requirement for signup but should be complete for profile visibility. It's maybe a me problem. πŸ˜„
  • lucasg-1319310752687063122

    Lucas G

    3 months ago

    That's a common flow which I think people would be fine with
  • lucasg-1319311034175062017

    Lucas G

    3 months ago

    Sign-up (basic form) -> activate profile by clicking link in email -> land on 'activate' page which has the profile form
  • tomthebigtree-1319311376703033354

    Tom Ireland

    3 months ago

    Yeah, this is exactly what I'm doing.
  • tomthebigtree-1319311634430431302

    Tom Ireland

    3 months ago

    Front end validation will suffice but looking to up my game and approach this with a pro mindset with security and data integrity in mind.
  • It's unlikely someone would go around the houses for something so trivial but don't want to make it an option. πŸ˜„
  • lucasg-1319312458040475789

    Lucas G

    3 months ago

    Then you'll need something in the middle to do additional checks
  • tomthebigtree-1319313104261353594

    Tom Ireland

    3 months ago

    Yeah, thinking Edge functions or CFWs might be the way. Got vscode setup locally and Supabase CLI with Docker but slightly out of my comfort zone. 🀒
  • lucasg-1319313477852201010

    Lucas G

    3 months ago

    I know the feeling
  • But it is how we grow as devs
  • tomthebigtree-1319314183895912541

    Tom Ireland

    3 months ago

    Very true, sir.

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code β€” but accessible to your entire team!

Try toddle β€” it's free!

Β© Copyright 2024 toddle. All rights reserved.