Skip to main content

Server Initialization Guide

Every DartWay project must initialize DartWay Core (DwCore) on the server side. This setup defines how the framework integrates with Serverpod, manages authentication, and configures CRUD operations.

Where it happens

Initialization is usually placed in a dedicated server bootstrap file (for example init.dart or main.dart in your server project).

late final DwCore<UserProfile> dw;

initDartwayCore(Serverpod serverpod) {
dw = DwCore.init<UserProfile>(
userProfileTable: UserProfile.t,
crudConfigurations: [userProfileCrudConfig],
userProfileConstructor: ({
required int userInfoId,
required DwAuthDataStash dwDataStash,
}) async =>
UserProfile(
userInfoId: userInfoId,
phone: dwDataStash.identifier,
firstName: dwDataStash.data['firstName'] ?? '',
conditionsAcceptedAt: DateTime.now(),
agreedForMarketingCommunications: bool.tryParse(
dwDataStash.data['agreedForMarketingCommunications'] ?? '') ??
false,
),
);

DwPhoneAuthConfig.set(DwPhoneAuthConfig.defaultDevelopmentConfig);
}

What happens here

  1. DwCore initialization

    • DwCore.init<UserProfile> bootstraps the DartWay Core layer and connects it with Serverpod.
    • It wires up CRUD configuration, authentication, and the current user profile model.
  2. User Profile table binding

    • userProfileTable: UserProfile.t tells DartWay which database table stores user profiles.
    • This enables automatic queries and CRUD operations for the profile.
  3. CRUD configuration

    • crudConfigurations: [userProfileCrudConfig] registers CRUD rules.
    • This controls which models are editable, what permissions apply, and how API endpoints are generated.

    !!! Add here all new configurations for your new models.

  4. User profile constructor

    • Defines how a UserProfile is created when a new user registers/authenticates.

    • Parameters:

      • userInfoId: ID from Serverpod’s auth system.
      • dwDataStash: contains auth provider data (phone/email, additional metadata).
    • The constructor builds a valid initial profile object with default values (phone, first name, agreements, etc.).

  5. Phone Auth configuration

    • DwPhoneAuthConfig.set(...) sets the authentication strategy.
    • In the snippet we use defaultDevelopmentConfig, but in production this should be replaced with a secure configuration (SMS provider, verification logic, etc.).

Summary

This initialization step ensures that:

  • DartWay Core knows about your main user model (UserProfile).
  • Authentication and profile creation are properly wired up.
  • CRUD endpoints are configured automatically.
  • The project has a consistent entry point for all user-related operations.

Without this setup, the app cannot handle users, profiles, or authentication correctly.