Replies: 1 comment
-
|
Draft Response (Copy & Paste): Hi there! Welcome to the Serverpod community. Moving from Node.js can be a paradigm shift, but once you get used to the "Serverpod way," it becomes very powerful. The approach you implemented by overriding startRegistration is not recommended. Why? startRegistration triggers before the user has verified their email (when they request the verification code). If you create your custom User record there, you will end up with "Ghost Users" in your database—people who requested a code but never actually completed the sign-up.
You want to create your custom user record only after the user is fully verified and the core UserInfo has been created by Serverpod. Modify your run function (usually in server.dart) to set up the AuthConfig with an onUserCreated callback. Here is the implementation: Dart // inside bin/main.dart (or wherever your run function is) void run(List args) async { // 1. Configure the Auth Hooks BEFORE initializing auth services )); // 2. Initialize Auth Services (Your existing code) await pod.start(); Data Integrity: You only create records for verified, real users. Separation of Concerns: Your Auth logic (Serverpod) stays separate from your Business logic (Your Custom User Table).
If you strictly require Username + Password login: Don't try to hack EmailIdp: It validates email formats. Create a Custom Endpoint: Since you are coming from Node.js, think of this as writing a custom Controller. Create a LoginEndpoint. Accept username and password. Find the user in your DB by username. Validate the password hash manually (Serverpod has PasswordManager utilities you can use). Manually create a session using session.auth.signInUser(...). However, for a smoother start, I highly recommend sticking to Email + Password as the primary identifier, as it simplifies security significantly. Hope this helps! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I’ve just started learning Serverpod, and I’ve run into some issues with authentication — mainly because I haven’t been able to find up-to-date information on how to work with the latest version.
Could you please advise on the correct way to approach my task?
I need to ensure that when a user signs in, we also create a corresponding user record in our own database.
So far, I’ve only come up with the following solution, but I’m not sure if it’s the right approach:
Also, how can I extend the authentication flow — for example, to support login using a username + password instead of only email?
I’m finding this system a bit difficult to understand. I previously worked with Node.js, and things there were structured very differently.
Beta Was this translation helpful? Give feedback.
All reactions