User registration
✅ Purpose of the scenario:
- We get the registration form for generating the frontend form
- The user enters the required data and registers.
- After registration, the user receives an activation code by email/sms
- The user enters the activation code and activates the created user.
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- Registration form with marker "reg"
- Form fields (attributes) with markers "email_reg", "password_reg", "name_reg", "phone_reg"
- Valid email/phone number to receive the activation code
📌 Important:
- We do not handle errors in these examples.
- You can handle errors in trycatch or in a construction like "await Promise.catch((error) => error)"
Scenario
1. Import oneEntry and define url and token
Example:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Creating an API client with defineOneEntry() function
Example:
const { Forms, FormData } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. We get a registration form with Forms.getFormByMarker() for generating a frontend form
Example:
const form = await Forms.getFormByMarker('reg');
Result:
{
"id": 4,
"attributeSetId": 5,
"type": "sing_in_up",
"localizeInfos": {
"title": "Registration",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 0,
"position": 1,
"identifier": "reg",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "string",
"marker": "email_reg",
"isLogin": true,
"isSignUp": false,
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
},
"emailInspectionValidator": true
},
"localizeInfos": {
"title": "E-mail"
},
"additionalFields": [],
"isNotificationEmail": false,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "string",
"marker": "name_reg",
"isLogin": null,
"isSignUp": true,
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"localizeInfos": {
"title": "Name"
},
"additionalFields": [],
"isNotificationEmail": false,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "string",
"marker": "phone_reg",
"isLogin": null,
"isSignUp": true,
"position": 3,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"localizeInfos": {
"title": "Phone"
},
"additionalFields": [],
"isNotificationEmail": false,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "string",
"marker": "password_reg",
"isLogin": null,
"isSignUp": null,
"position": 4,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
},
"stringInspectionValidator": {
"stringMax": 0,
"stringMin": 0,
"stringLength": 0
}
},
"localizeInfos": {
"title": "Password"
},
"additionalFields": [],
"isNotificationEmail": false,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "string",
"marker": "email_notification_reg",
"isLogin": null,
"isSignUp": null,
"position": 5,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "email for notification"
},
"additionalFields": [],
"isNotificationEmail": true,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}
4. Preparing data for user registration and registrer user with AuthProvider.signUp()
Data:
{
"formIdentifier": "reg",
"authData": [
{
"marker": "email_reg",
"value": "your-user@email.com"
},
{
"marker": "password_reg",
"value": "123456"
}
],
"formData": {
"en_US": [
{
"marker": "name_reg",
"type": "string",
"value": "UserName"
},
{
"marker": "phone_reg",
"type": "string",
"value": "+18007986545"
},
{
"marker": "email_notification_reg",
"type": "string",
"value": "your-user@email.com"
}
]
},
"notificationData": {
"email": "your-user@email.com",
"phonePush": [],
"phoneSMS": "+18007986545"
},
"langCode": "en_US"
}
Example:
const newUser = await AuthProvider.signUp('email', registrationData);
Result:
{
"identifier": "your-user@email.com",
"isActive": false,
"formData": [
{
"marker": "name_reg",
"type": "string",
"value": "UserName"
},
{
"marker": "phone_reg",
"type": "string",
"value": "+18007986545"
},
{
"marker": "email_notification_reg",
"type": "string",
"value": "your-user@email.com"
}
],
"notificationData": {
"email": "your-user@email.com",
"phonePush": [],
"phoneSMS": "+18007986545"
},
"locale": "en_US",
"updatedDate": "2025-04-30T20:07:38.156Z",
"deletedAt": null,
"id": 33,
"version": 0,
"state": {}
}
5. Generate a confirmation code with AuthProvider.generateCode() send to email/sms
Data:
your-user@email.com
Example:
const generateCode = await AuthProvider.generateCode('email', emailReg, 'auth');
Result:
{
"statusCode": 400,
"timestamp": "2025-04-30T20:07:39.755Z",
"message": "User already has a code",
"pageData": null
}
6. User enters code → verification
Example:
const code = prompt('Enter verification code:') as string;
7. Check code with AuthProvider.checkCode() If code is correct activate user
Example:
const isCorrect = await AuthProvider.checkCode(
'email',
emailReg,
'1',
code,
);
if (isCorrect) {
await AuthProvider.activateUser('email', emailReg, code);
console.log('✅ User activated!');
} else {
console.log('❌ Invalid verification code');
}
8. User authentication with AuthProvider.auth()
Example:
const authResponse = await AuthProvider.auth('email', {
authData,
});
Result:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}
Final example
// 1. Import oneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
const emailReg = 'your-user@email.com';
// 2. Creating an API client:
const { Forms, AuthProvider } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. We get a registration form with custom fields for generating a frontend form
const form = await Forms.getFormByMarker('reg');
// 4. Preparing data for user registration and user registration
const authData = [
{
marker: 'email_reg',
value: 'your-user@email.com',
},
{
marker: 'password_reg',
value: '123456',
},
];
const formData = [
{
marker: 'name_reg',
type: 'string',
value: 'UserName',
},
{
marker: 'phone_reg',
type: 'string',
value: '+18007986545',
},
{
marker: 'email_notification_reg',
type: 'string',
value: emailReg,
},
];
const notificationData = {
email: emailReg,
phonePush: [],
phoneSMS: '+18007986545',
};
const registrationData = {
formIdentifier: 'reg',
authData: authData,
formData: formData,
notificationData: notificationData,
};
let newUser = await AuthProvider.signUp('email', registrationData);
// 5. Generate a confirmation code (send to email)
let generateCode = await AuthProvider.generateCode('email', emailReg, 'auth');
// 6. User enters code → verification
const code = prompt('Enter verification code:') as string;
// 7. User activation
const isCorrect = await AuthProvider.checkCode(
'email',
emailReg,
'1',
code,
);
if (isCorrect) {
await AuthProvider.activateUser('email', emailReg, code);
console.log('✅ User activated!');
} else {
console.log('❌ Invalid verification code');
}
// 8. User authentication
const authResponse = await AuthProvider.auth('email', {
authData,
});
console.log(authResponse);