Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 0.16.0

* Deprecate `createVerification` method in `Account` service
* Add `createEmailVerification` method in `Account` service

## 0.11.0

* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service
Expand Down
13 changes: 13 additions & 0 deletions docs/examples/account/create-email-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Client, Account } from "react-native-appwrite";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.createEmailVerification({
url: 'https://example.com'
});

console.log(result);
14 changes: 14 additions & 0 deletions docs/examples/account/update-email-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Client, Account } from "react-native-appwrite";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const account = new Account(client);

const result = await account.updateEmailVerification({
userId: '<USER_ID>',
secret: '<SECRET>'
});

console.log(result);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-native-appwrite",
"homepage": "https://appwrite.io/support",
"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",
"version": "0.15.0",
"version": "0.16.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Client {
'x-sdk-name': 'React Native',
'x-sdk-platform': 'client',
'x-sdk-language': 'reactnative',
'x-sdk-version': '0.15.0',
'x-sdk-version': '0.16.0',
'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down
127 changes: 123 additions & 4 deletions src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,62 @@ export class Account extends Service {
* @throws {AppwriteException}
* @returns {Promise}
*/
createEmailVerification(params: { url: string }): Promise<Models.Token>;
/**
* 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.
*
* 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.
*
*
* @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.
* @throws {AppwriteException}
* @returns {Promise<Models.Token>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createEmailVerification(url: string): Promise<Models.Token>;
createEmailVerification(
paramsOrFirst: { url: string } | string
): Promise<Models.Token> {
let params: { url: string };

if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { url: string };
} else {
params = {
url: paramsOrFirst as string
};
}

const url = params.url;

if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}

const apiPath = '/account/verifications/email';
const payload: Payload = {};

if (typeof url !== 'undefined') {
payload['url'] = url;
}

const uri = new URL(this.client.config.endpoint + apiPath);
return this.client.call('post', uri, {
'content-type': 'application/json',
}, payload);
}

/**
* 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.
*
* 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.
*
*
* @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.
* @throws {AppwriteException}
* @returns {Promise}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.
*/
createVerification(params: { url: string }): Promise<Models.Token>;
/**
* 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.
Expand Down Expand Up @@ -2459,7 +2515,7 @@ export class Account extends Service {
throw new AppwriteException('Missing required parameter: "url"');
}

const apiPath = '/account/verification';
const apiPath = '/account/verifications/email';
const payload: Payload = {};

if (typeof url !== 'undefined') {
Expand All @@ -2480,6 +2536,69 @@ export class Account extends Service {
* @throws {AppwriteException}
* @returns {Promise}
*/
updateEmailVerification(params: { userId: string, secret: string }): Promise<Models.Token>;
/**
* 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.
*
* @param {string} userId - User ID.
* @param {string} secret - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.Token>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateEmailVerification(userId: string, secret: string): Promise<Models.Token>;
updateEmailVerification(
paramsOrFirst: { userId: string, secret: string } | string,
...rest: [(string)?]
): Promise<Models.Token> {
let params: { userId: string, secret: string };

if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { userId: string, secret: string };
} else {
params = {
userId: paramsOrFirst as string,
secret: rest[0] as string
};
}

const userId = params.userId;
const secret = params.secret;

if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}

if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}

const apiPath = '/account/verifications/email';
const payload: Payload = {};

if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}

if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}

const uri = new URL(this.client.config.endpoint + apiPath);
return this.client.call('put', uri, {
'content-type': 'application/json',
}, payload);
}

/**
* 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.
*
* @param {string} params.userId - User ID.
* @param {string} params.secret - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.
*/
updateVerification(params: { userId: string, secret: string }): Promise<Models.Token>;
/**
* 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.
Expand Down Expand Up @@ -2517,7 +2636,7 @@ export class Account extends Service {
throw new AppwriteException('Missing required parameter: "secret"');
}

const apiPath = '/account/verification';
const apiPath = '/account/verifications/email';
const payload: Payload = {};

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

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

const apiPath = '/account/verification/phone';
const apiPath = '/account/verifications/phone';
const payload: Payload = {};

if (typeof userId !== 'undefined') {
Expand Down
Loading