Resolve "146-Failed to register a tutor"
I updated /tutor/register
to make it work like /register
using Actions, just like we do in +page.server.ts
. I created a new file tutor/register/+page.server.ts
where I moved all the logic for registering a tutor, logging them in immediately after, and fetching their user data. This way, everything happens on the server side, making it cleaner.
In tutor/register/+page.svelte
, I removed the onRegister
function because it’s no longer needed. The form now directly works with the action in the server file. I also want to point out that I didn’t use the User instance from the frontend. I just patched the data directly on the server using patchUserAPI
. I left the User instance commented out for now in case we need to revisit it later.
With these changes, the tutor registration flow works perfectly. The tutor gets registered, logged in, and their data is fetched without any issues.
One thing I noticed is that the logic for tutor registration is almost the same as the regular user registration. Now, there’s a bit of copy-paste, so I’ll open a new issue to make the registration process more modular.