WRDAuth setup
You need to update your wrdschema definition to import the authentication schema, and specify the accounttype and fields to use. An example that uses the emailfield for both login and email:
<schemadefinition xmlns="http://www.webhare.net/xmlns/wrd/schemadefinition"
accounttype="wrd_person"
accountloginfield="wrd_contact_email"
accountemailfield="wrd_contact_email"
accountpasswordfield="password">
<object tag="wrd_person">
<attributes>
<datetime tag="lastlogin" title="Last login" />
<email tag="wrd_contact_email" required="1" title="E-mail" unique="1" />
<authenticationsettings tag="password" title="Password" />
</attributes>
</object>
</schemadefinition>
The accounttype should always be WRD_PERSON. Other types are not fully supported.
Siteprofile WRD auth
<wrdauth xmlns="http://www.webhare.net/xmlns/wrd"
wrdschema="YOURSCHEMA"
cookiename="webharelogin-YOURCOOKIE"
lastloginfield="LASTLOGIN" />
cookiename must be a string starting with webharelogin- and not contain any underscores
Optional attributes:
- cachefields: a space-separated list of WRD fields from the loggedin entity to store in the user info (refreshed at login or session restoration)
- customizer: reference to a support object to handle authentication, eg to override the JavaScript userinfo
- passwordresetlifetime: how long a password reset link is valid, in minutes. defaults to 3 days
An example support object, linked using customizer="auth.ts#WRDAuthCustomer"
:
import type { AuthCustomizer, IsAllowedToLoginParameters, LoginDeniedInfo } from "@webhare/auth";
export class WRDAuthCustomer implements AuthCustomizer {
async isAllowedToLogin(params: IsAllowedToLoginParameters): Promise<LoginDeniedInfo | null> {
const { wrdContactEmail } = await params.wrdSchema.getFields("wrdPerson", params.user, ["wrdContactEmail"]);
if (wrdContactEmail.includes("logindenied"))
return { code: "internal-error", error: "Account is disliked" };
return null;
}
}