Skip to content

Commit 90948c5

Browse files
authored
Merge pull request #76 from appwrite/dev
feat: React Native SDK update for version 0.16.0
2 parents a783ec5 + 1e79e94 commit 90948c5

File tree

7 files changed

+169
-18
lines changed

7 files changed

+169
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
## 0.16.0
4+
5+
* Deprecate `createVerification` method in `Account` service
6+
* Add `createEmailVerification` method in `Account` service
7+
38
## 0.11.0
49

510
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Client, Account } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const account = new Account(client);
8+
9+
const result = await account.createEmailVerification({
10+
url: 'https://example.com'
11+
});
12+
13+
console.log(result);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Client, Account } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const account = new Account(client);
8+
9+
const result = await account.updateEmailVerification({
10+
userId: '<USER_ID>',
11+
secret: '<SECRET>'
12+
});
13+
14+
console.log(result);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-native-appwrite",
33
"homepage": "https://appwrite.io/support",
44
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5-
"version": "0.15.0",
5+
"version": "0.16.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Client {
115115
'x-sdk-name': 'React Native',
116116
'x-sdk-platform': 'client',
117117
'x-sdk-language': 'reactnative',
118-
'x-sdk-version': '0.15.0',
118+
'x-sdk-version': '0.16.0',
119119
'X-Appwrite-Response-Format': '1.8.0',
120120
};
121121

src/services/account.ts

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,62 @@ export class Account extends Service {
24272427
* @throws {AppwriteException}
24282428
* @returns {Promise}
24292429
*/
2430+
createEmailVerification(params: { url: string }): Promise<Models.Token>;
2431+
/**
2432+
* Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
2433+
*
2434+
* Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
2435+
*
2436+
*
2437+
* @param {string} url - URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.
2438+
* @throws {AppwriteException}
2439+
* @returns {Promise<Models.Token>}
2440+
* @deprecated Use the object parameter style method for a better developer experience.
2441+
*/
2442+
createEmailVerification(url: string): Promise<Models.Token>;
2443+
createEmailVerification(
2444+
paramsOrFirst: { url: string } | string
2445+
): Promise<Models.Token> {
2446+
let params: { url: string };
2447+
2448+
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
2449+
params = (paramsOrFirst || {}) as { url: string };
2450+
} else {
2451+
params = {
2452+
url: paramsOrFirst as string
2453+
};
2454+
}
2455+
2456+
const url = params.url;
2457+
2458+
if (typeof url === 'undefined') {
2459+
throw new AppwriteException('Missing required parameter: "url"');
2460+
}
2461+
2462+
const apiPath = '/account/verifications/email';
2463+
const payload: Payload = {};
2464+
2465+
if (typeof url !== 'undefined') {
2466+
payload['url'] = url;
2467+
}
2468+
2469+
const uri = new URL(this.client.config.endpoint + apiPath);
2470+
return this.client.call('post', uri, {
2471+
'content-type': 'application/json',
2472+
}, payload);
2473+
}
2474+
2475+
/**
2476+
* Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
2477+
*
2478+
* Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
2479+
*
2480+
*
2481+
* @param {string} params.url - URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.
2482+
* @throws {AppwriteException}
2483+
* @returns {Promise}
2484+
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.
2485+
*/
24302486
createVerification(params: { url: string }): Promise<Models.Token>;
24312487
/**
24322488
* Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
@@ -2459,7 +2515,7 @@ export class Account extends Service {
24592515
throw new AppwriteException('Missing required parameter: "url"');
24602516
}
24612517

2462-
const apiPath = '/account/verification';
2518+
const apiPath = '/account/verifications/email';
24632519
const payload: Payload = {};
24642520

24652521
if (typeof url !== 'undefined') {
@@ -2480,6 +2536,69 @@ export class Account extends Service {
24802536
* @throws {AppwriteException}
24812537
* @returns {Promise}
24822538
*/
2539+
updateEmailVerification(params: { userId: string, secret: string }): Promise<Models.Token>;
2540+
/**
2541+
* Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
2542+
*
2543+
* @param {string} userId - User ID.
2544+
* @param {string} secret - Valid verification token.
2545+
* @throws {AppwriteException}
2546+
* @returns {Promise<Models.Token>}
2547+
* @deprecated Use the object parameter style method for a better developer experience.
2548+
*/
2549+
updateEmailVerification(userId: string, secret: string): Promise<Models.Token>;
2550+
updateEmailVerification(
2551+
paramsOrFirst: { userId: string, secret: string } | string,
2552+
...rest: [(string)?]
2553+
): Promise<Models.Token> {
2554+
let params: { userId: string, secret: string };
2555+
2556+
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
2557+
params = (paramsOrFirst || {}) as { userId: string, secret: string };
2558+
} else {
2559+
params = {
2560+
userId: paramsOrFirst as string,
2561+
secret: rest[0] as string
2562+
};
2563+
}
2564+
2565+
const userId = params.userId;
2566+
const secret = params.secret;
2567+
2568+
if (typeof userId === 'undefined') {
2569+
throw new AppwriteException('Missing required parameter: "userId"');
2570+
}
2571+
2572+
if (typeof secret === 'undefined') {
2573+
throw new AppwriteException('Missing required parameter: "secret"');
2574+
}
2575+
2576+
const apiPath = '/account/verifications/email';
2577+
const payload: Payload = {};
2578+
2579+
if (typeof userId !== 'undefined') {
2580+
payload['userId'] = userId;
2581+
}
2582+
2583+
if (typeof secret !== 'undefined') {
2584+
payload['secret'] = secret;
2585+
}
2586+
2587+
const uri = new URL(this.client.config.endpoint + apiPath);
2588+
return this.client.call('put', uri, {
2589+
'content-type': 'application/json',
2590+
}, payload);
2591+
}
2592+
2593+
/**
2594+
* Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
2595+
*
2596+
* @param {string} params.userId - User ID.
2597+
* @param {string} params.secret - Valid verification token.
2598+
* @throws {AppwriteException}
2599+
* @returns {Promise}
2600+
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.
2601+
*/
24832602
updateVerification(params: { userId: string, secret: string }): Promise<Models.Token>;
24842603
/**
24852604
* Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
@@ -2517,7 +2636,7 @@ export class Account extends Service {
25172636
throw new AppwriteException('Missing required parameter: "secret"');
25182637
}
25192638

2520-
const apiPath = '/account/verification';
2639+
const apiPath = '/account/verifications/email';
25212640
const payload: Payload = {};
25222641

25232642
if (typeof userId !== 'undefined') {
@@ -2541,7 +2660,7 @@ export class Account extends Service {
25412660
* @returns {Promise}
25422661
*/
25432662
createPhoneVerification(): Promise<Models.Token> {
2544-
const apiPath = '/account/verification/phone';
2663+
const apiPath = '/account/verifications/phone';
25452664
const payload: Payload = {};
25462665

25472666
const uri = new URL(this.client.config.endpoint + apiPath);
@@ -2595,7 +2714,7 @@ export class Account extends Service {
25952714
throw new AppwriteException('Missing required parameter: "secret"');
25962715
}
25972716

2598-
const apiPath = '/account/verification/phone';
2717+
const apiPath = '/account/verifications/phone';
25992718
const payload: Payload = {};
26002719

26012720
if (typeof userId !== 'undefined') {

0 commit comments

Comments
 (0)