From 24f6921ed2ac588a5ebfc7de4ce5f70e95ce0769 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 11 Feb 2024 20:22:17 +0530 Subject: [PATCH] feat: initial commit --- src/lib/actions/analytics.ts | 1 + src/lib/sdk/auth.ts | 35 ++++ src/lib/stores/sdk.ts | 2 + .../auth/security/+page.svelte | 2 + .../auth/security/updateMockNumbers.svelte | 166 ++++++++++++++++++ src/routes/console/project-[project]/store.ts | 4 +- 6 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 src/lib/sdk/auth.ts create mode 100644 src/routes/console/project-[project]/auth/security/updateMockNumbers.svelte diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 181592ef0..0d9b8bccd 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -183,6 +183,7 @@ export enum Submit { AuthPasswordHistoryUpdate = 'submit_auth_password_history_limit_update', AuthPasswordDictionaryUpdate = 'submit_auth_password_dictionary_update', AuthPersonalDataCheckUpdate = 'submit_auth_personal_data_check_update', + AuthMockNumbersUpdate = 'submit_auth_mock_numbers_update', SessionsLengthUpdate = 'submit_sessions_length_update', SessionsLimitUpdate = 'submit_sessions_limit_update', SessionDelete = 'submit_session_delete', diff --git a/src/lib/sdk/auth.ts b/src/lib/sdk/auth.ts new file mode 100644 index 000000000..4a77a485c --- /dev/null +++ b/src/lib/sdk/auth.ts @@ -0,0 +1,35 @@ +import type { Client, Models } from '@appwrite.io/console'; + +export type MockNumber = { + phone: string; + otp: string; +}; + +export type Project = Models.Project & { + authMockNumbers: MockNumber[]; +}; + +export class Auth { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + async updateMockNumbers(projectId: string, numbers: MockNumber[]): Promise { + const path = `/projects/${projectId}/auth/mock-numbers`; + const params = { + projectId, + numbers: numbers + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'patch', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } +} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index caacafee7..aff27ae5a 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -21,6 +21,7 @@ import { Vcs } from '@appwrite.io/console'; import { Billing } from '../sdk/billing'; +import { Auth } from '$lib/sdk/auth'; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; @@ -65,6 +66,7 @@ export const sdk = { health: new Health(clientConsole), locale: new Locale(clientConsole), projects: new Projects(clientConsole), + auth: new Auth(clientConsole), teams: new Teams(clientConsole), users: new Users(clientConsole), migrations: new Migrations(clientConsole), diff --git a/src/routes/console/project-[project]/auth/security/+page.svelte b/src/routes/console/project-[project]/auth/security/+page.svelte index f69b91395..0e3ac4f68 100644 --- a/src/routes/console/project-[project]/auth/security/+page.svelte +++ b/src/routes/console/project-[project]/auth/security/+page.svelte @@ -1,5 +1,6 @@ + + + Mock Phone Numbers +

+ Create upto 10 mock phone numbers and verification codes for testing. These numbers + can be used to simulate the phone number verification without sending an SMS. +

+ + + + Use Mock phone numbers with caution + Please use fictious phone numbers and verification codes to avoid affecting real user accounts. + + + +
    + + + +
+
+ + {#if $numbers.length > 0} + + + Phone Number + Verification Code + + + + {#each $numbers as number, i} + + + + {number.phone} + + + + + + {number.otp} + + + + +
+ +
+
+
+ {/each} +
+
+ {/if} +
+ + + + +
diff --git a/src/routes/console/project-[project]/store.ts b/src/routes/console/project-[project]/store.ts index 6af331f1c..18d6eee6d 100644 --- a/src/routes/console/project-[project]/store.ts +++ b/src/routes/console/project-[project]/store.ts @@ -1,11 +1,11 @@ import { page } from '$app/stores'; -import type { Models } from '@appwrite.io/console'; +import type { Project } from '$lib/sdk/auth'; import type { BarSeriesOption } from 'echarts/charts'; import { derived, writable } from 'svelte/store'; export const project = derived( page, - ($page) => $page.data.project as Models.Project & { region?: string } + ($page) => $page.data.project as Project & { region?: string } ); export const onboarding = derived( project,