Skip to main content

createFdmAuth

@svenvw/fdm-source


@svenvw/fdm-source / fdm-core/src / createFdmAuth

Function: createFdmAuth()

createFdmAuth(fdm, google?, microsoft?, sendMagicLinkEmail?, emailAndPassword?): any

Defined in: fdm-core/src/authentication.ts:28

Initializes and configures the authentication system for the FDM application using Better Auth.

This function sets up the Better Auth system with a PostgreSQL database adapter and a custom schema, allowing users to authenticate via social providers like Google and Microsoft, or optionally with email and password. It configures additional user fields (firstname, surname, lang, farm_active), and manages session parameters with a 30-day expiration and daily update. It also defines mappings from social provider profiles to user formats, extracting relevant user information.

Parameters

fdm

any

The FDM instance providing the connection to the database. The instance can be created with createFdmServer.

google?

Optional configuration for Google authentication. If provided, users can sign up and sign in with their Google accounts.

clientId

string

clientSecret

string

microsoft?

Optional configuration for Microsoft authentication. If provided, users can sign up and sign in with their Microsoft accounts.

clientId

string

clientSecret

string

sendMagicLinkEmail?

(email, url) => Promise<void>

Optional function to send magic link emails. If provided, the magic link plugin will use this function to send emails.

emailAndPassword?

boolean

Optional boolean indicating whether to enable email and password authentication. Defaults to false.

Returns

any

The configured authentication instance.

Throws

If required environment variables are missing or if role assignment fails.