@Costas there are several threads on the site but I will try to direct you towards a definitive one.
It contains a sketch written by @Costas so it must be pretty good
Even I struggle to find some of the threads but I do remember that there is a function called mywifi().
Quick search brings up this thread Check connection status in loop and reconect
It tries to cover all eventualities so it is more than a couple of lines and you can probably cut it down a bit but most lines of code do serve some purpose.