221
Views
6
Comments
Solved
Reminder  TODO: Validate data before saving it to the database
Question

How to validate when i am already inside a server action ! and not on the client side 



2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @Omar AbdElhadi ,

this note only refers to server side validation, you don't need to be on the client.

you want your data to be of a minimum quality, you don't want database errors to go off because it is not of good quality, but validation can go beyond just checking database level rules, it should ideally check all business rules that are applicable to your data, at a point on the server, close to and before going ahead with the create or update or ....

you should not rely on client side validation for this, for 2 reasons

  • your end user can tamper with client data
  • you have no guarantee that your server action will only be used by that one screen where you carefully crafted it in such a way that no bad data can come from it.  At any point in the future, other developers or you could re-use the same server action to create records from an integration / timer / process / other less well designed screen /...

Dorine

2021-09-06 15-09-53
Dorine Boudry
 
MVP

for further reading, see these articles from @Justin James 

UserImage.jpg
Omar AbdElhadi

Thanks for reply , but this server action is called inside service , not inside client action , so how to solve it in that case ?

2021-09-06 15-09-53
Dorine Boudry
 
MVP

solve what ?

UserImage.jpg
Omar AbdElhadi


i dont have cleint action inside the service module ! 
all of them are server actions so how to fix it insider the server actions 

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Read previous answer again : this is in no way related to any client action, it is about validating ( i.e. checking correct value of) data on server side before  going ahead with saving things in the database.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.