From 21cb4e4da778c3c6cea64ffca3203150c3a9116e Mon Sep 17 00:00:00 2001 From: Ota Prokopec Date: Tue, 14 Mar 2023 18:35:03 +0100 Subject: [PATCH] fix --- src/App.svelte | 2 +- src/lib/components/erant/Button.svelte | 10 ++++++ src/lib/utils/appwrite/authorizationErrors.ts | 8 +++++ src/lib/utils/database/users.ts | 6 ++++ src/routes/register/createAccount.svelte | 2 +- src/routes/register/register.svelte | 36 +++++++++++++------ 6 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 src/lib/components/erant/Button.svelte create mode 100644 src/lib/utils/appwrite/authorizationErrors.ts create mode 100644 src/lib/utils/database/users.ts diff --git a/src/App.svelte b/src/App.svelte index c4f3bd9..e88bdc4 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -12,7 +12,7 @@ let isMounted = false $: isReady = $localeLoading === false && $authLoading === false && isMounted - $: if (isReady && $user?.emailVerification) { + $: if (isReady && !$user?.emailVerification) { console.log('change') if (!location.pathname.startsWith('/login') && !location.pathname.startsWith('/register')) { diff --git a/src/lib/components/erant/Button.svelte b/src/lib/components/erant/Button.svelte new file mode 100644 index 0000000..c48ee4f --- /dev/null +++ b/src/lib/components/erant/Button.svelte @@ -0,0 +1,10 @@ + + + diff --git a/src/lib/utils/appwrite/authorizationErrors.ts b/src/lib/utils/appwrite/authorizationErrors.ts new file mode 100644 index 0000000..bb17f70 --- /dev/null +++ b/src/lib/utils/appwrite/authorizationErrors.ts @@ -0,0 +1,8 @@ +export const errors = { + 1001: 'Nickname is already taken', + 409: 'A user with the same email already is in Erant', +} + +export const getErrorMessage = (code: number) => { + return errors[code] +} diff --git a/src/lib/utils/database/users.ts b/src/lib/utils/database/users.ts new file mode 100644 index 0000000..db2b473 --- /dev/null +++ b/src/lib/utils/database/users.ts @@ -0,0 +1,6 @@ +import { databases } from '$lib/appwrite' +import { Query } from 'appwrite' + +export const getUserByErantId = async (erantId: string) => { + return (await databases.listDocuments('63ded6c18e8493bffc83', 'Users', [Query.equal('erantId', erantId)])).documents[0] +} diff --git a/src/routes/register/createAccount.svelte b/src/routes/register/createAccount.svelte index 45f3e3b..74a23c3 100644 --- a/src/routes/register/createAccount.svelte +++ b/src/routes/register/createAccount.svelte @@ -12,7 +12,7 @@ userName: $user.name, userId: $user.$id, }, - [Permission.delete(Role.user($user.$id)), Permission.update(Role.user($user.$id))], + [Permission.delete(Role.user($user.$id)), Permission.update(Role.user($user.$id)), Permission.read(Role.users('verified'))], ) navigate('/') })() diff --git a/src/routes/register/register.svelte b/src/routes/register/register.svelte index 62a4e37..6925a4f 100644 --- a/src/routes/register/register.svelte +++ b/src/routes/register/register.svelte @@ -1,8 +1,10 @@