Ana içeriğe geç

Kullanıcı kaydı

✅ Senaryonun amacı:

  • Ön uç formunu oluşturmak için kayıt formunu alıyoruz.
  • Kullanıcı gerekli verileri girer ve kaydolur.
  • Kayıttan sonra kullanıcıya e-posta/sms ile bir aktivasyon kodu gönderilir.
  • Kullanıcı aktivasyon kodunu girer ve oluşturulan kullanıcıyı aktifleştirir.

✅ Gerekenler:

  • OneEntry API ile kimlik doğrulama için geçerli bir PROJECT_URL ve APP_TOKEN.
  • "reg" işaretine sahip kayıt formu.
  • "email_reg", "password_reg", "name_reg", "phone_reg" işaretlerine sahip form alanları (özellikler).
  • Aktivasyon kodunu almak için geçerli bir e-posta/telefon numarası.

📌 Önemli:

  • Bu örneklerde hataları ele almıyoruz.
  • Hataları trycatch içinde veya "await Promise.catch((error) => error)" gibi bir yapı ile ele alabilirsiniz.

Senaryo

1. oneEntry'yi içe aktarın ve url ile token'ı tanımlayın

Örnek:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. defineOneEntry() fonksiyonu ile bir API istemcisi oluşturma

Örnek:

const { Forms, FormData } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. Ön uç formunu oluşturmak için Forms.getFormByMarker() ile bir kayıt formu alıyoruz

Örnek:

const form = await Forms.getFormByMarker('reg');
Sonuç:
{
"id": 4,
"attributeSetId": 5,
"type": "sing_in_up",
"localizeInfos": {
"title": "Kayıt",
"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-posta"
},
"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": "İsim"
},
"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": "Telefon"
},
"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": "Şifre"
},
"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": "Bildirim için e-posta"
},
"additionalFields": [],
"isNotificationEmail": true,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}

4. Kullanıcı kaydı için verileri hazırlama ve AuthProvider.signUp() ile kullanıcıyı kaydetme

Veri:

{
"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"
}

Örnek:

const newUser = await AuthProvider.signUp('email', registrationData);
Sonuç:
{
"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. AuthProvider.generateCode() ile bir onay kodu oluşturma ve e-posta/sms ile gönderme

Veri:

your-user@email.com

Örnek:

const generateCode = await AuthProvider.generateCode('email', emailReg, 'auth');
Sonuç:
{
"statusCode": 400,
"timestamp": "2025-04-30T20:07:39.755Z",
"message": "Kullanıcının zaten bir kodu var",
"pageData": null
}

6. Kullanıcı kodu girer → doğrulama

Örnek:

const code = prompt('Doğrulama kodunu girin:') as string;

7. AuthProvider.checkCode() ile kodu kontrol etme. Eğer kod doğruysa kullanıcıyı aktifleştir

Örnek:

const isCorrect = await AuthProvider.checkCode(
'email',
emailReg,
'1',
code,
);
if (isCorrect) {
await AuthProvider.activateUser('email', emailReg, code);
console.log('✅ Kullanıcı aktifleştirildi!');
} else {
console.log('❌ Geçersiz doğrulama kodu');
}

8. AuthProvider.auth() ile kullanıcı kimlik doğrulaması

Örnek:

const authResponse = await AuthProvider.auth('email', {
authData,
});
Sonuç:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}

Son örnek

// 1. oneEntry'yi içe aktarın ve PROJECT_URL ile APP_TOKEN'ı tanımlayın
import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

const emailReg = 'your-user@email.com';

// 2. Bir API istemcisi oluşturma:
const { Forms, AuthProvider } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. Ön uç formunu oluşturmak için özel alanlarla bir kayıt formu alıyoruz
const form = await Forms.getFormByMarker('reg');

// 4. Kullanıcı kaydı için verileri hazırlama ve kullanıcı kaydı
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. Onay kodu oluşturma (e-postaya gönder)
let generateCode = await AuthProvider.generateCode('email', emailReg, 'auth');

// 6. Kullanıcı kodu girer → doğrulama
const code = prompt('Doğrulama kodunu girin:') as string;

// 7. Kullanıcı aktifleştirme
const isCorrect = await AuthProvider.checkCode(
'email',
emailReg,
'1',
code,
);

if (isCorrect) {
await AuthProvider.activateUser('email', emailReg, code);
console.log('✅ Kullanıcı aktifleştirildi!');
} else {
console.log('❌ Geçersiz doğrulama kodu');
}

// 8. Kullanıcı kimlik doğrulaması
const authResponse = await AuthProvider.auth('email', {
authData,
});
console.log(authResponse);