After instantiating the SDK (which is explained here), you’re allowed to use the following methods from auth.email.
Initiate email authentication
When the initialize method is called, an email is sent to the specified address. The email will contain either a one-time code or a link, depending on the authentication method selected in the fourt.io dashboard.
initialize()
Parameters
EmailInitializeAuthParams object containing:
email- The email address of the user who wants to authenticate.redirectUrl(optional) - The URL to which the user will be redirected after completing the authentication process. It only needs to be provided if you are using link-based authentication.expirationSeconds(optional) - The number of seconds before the authentication request expires. Default is 900 seconds (15 minutes).
Returns
Promise<EmailAuthReturn>
Where EmailAuthReturn is an object containing:
method- The authentication method used, eithermagicLinkorotp.
Example
const initializeEmailAuth = await sdk.auth.email.initialize({
email: 'user-email@test.com',
redirectUrl: 'https://fourt.io',
expirationSeconds: 900,
})Complete email authentication
When the complete method is called, the authentication process is finalized using the parameters received.
Depending on the email authentication method selected, you will need to use either magicLink.complete() or otp.complete().
magicLink.complete()
To be used when link-based authentication is selected.
Parameters
The parameters are received as URL params, which are necessary to complete the authentication process.
CompleteAuthWithBundleParams object containing:
bundlesubOrgId
Returns
Promise<void>
Example
const completeEmailAuth = await sdk.auth.email.magicLink.complete({
bundle: 'BUNDLE_ID',
subOrgId: 'SUB_ORG_ID',
})otp.complete()
To be used when one-time code-based authentication is selected.
Parameters
CompleteAuthWithOtpParams object containing:
email- The email address of the user who wants to authenticate.otpCode- The one-time code sent to the user’s email.
Returns
Promise<void>
Example
const completeEmailAuth = await sdk.auth.email.otp.complete({
email: 'user-email@test.com',
otpCode: 'OTP_CODE',
})