From 2978272010c6eef4dc2eaab41ef839935b0d517f Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 14 Nov 2022 23:15:19 +0100 Subject: [PATCH 1/6] feat: session length --- package-lock.json | 14 ++++++------- package.json | 2 +- src/lib/helpers/timeConversion.ts | 21 +++++++++++++++++++ .../auth/security/+page.svelte | 21 ++++++++++++------- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 330a768fc1..7cf587e67b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@aw-labs/appwrite-console": "^11.0.0", + "@aw-labs/appwrite-console": "^12.0.0", "@aw-labs/icons": "0.0.0-77", "@aw-labs/ui": "0.0.0-77", "@popperjs/core": "^2.11.6", @@ -145,9 +145,9 @@ "integrity": "sha512-1Yw7u/COtxx06BfwlI+kVhsa/upKYzmCNrT4c8QDeCY2KMYlnijkUjtHiPU08HxyTIVB5j6d75O0YWVIHwQS8g==" }, "node_modules/@aw-labs/appwrite-console": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-11.0.0.tgz", - "integrity": "sha512-V9cI4j6YdvMbM2xCUp0JGHd1B2KEJ3T8rqSVdPecfVBrRn8S2BcwJsJGUJCixca0uhrK+6+IlARShaGegyAiGA==", + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-12.0.0.tgz", + "integrity": "sha512-GEXTpKG4vAMjsf0iGSi/ilsTpjHtc12gA/zbM/mqQU6SdimFaTSKNYg0wu6CM6+afM3jWvEEehB//1WY8mhh5g==", "dependencies": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" @@ -7740,9 +7740,9 @@ "integrity": "sha512-1Yw7u/COtxx06BfwlI+kVhsa/upKYzmCNrT4c8QDeCY2KMYlnijkUjtHiPU08HxyTIVB5j6d75O0YWVIHwQS8g==" }, "@aw-labs/appwrite-console": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-11.0.0.tgz", - "integrity": "sha512-V9cI4j6YdvMbM2xCUp0JGHd1B2KEJ3T8rqSVdPecfVBrRn8S2BcwJsJGUJCixca0uhrK+6+IlARShaGegyAiGA==", + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-12.0.0.tgz", + "integrity": "sha512-GEXTpKG4vAMjsf0iGSi/ilsTpjHtc12gA/zbM/mqQU6SdimFaTSKNYg0wu6CM6+afM3jWvEEehB//1WY8mhh5g==", "requires": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" diff --git a/package.json b/package.json index e20a05bdae..70906a7523 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@analytics/google-analytics": "^1.0.5", "analytics": "^0.8.1", - "@aw-labs/appwrite-console": "^11.0.0", + "@aw-labs/appwrite-console": "^12.0.0", "@aw-labs/icons": "0.0.0-77", "@aw-labs/ui": "0.0.0-77", "@popperjs/core": "^2.11.6", diff --git a/src/lib/helpers/timeConversion.ts b/src/lib/helpers/timeConversion.ts index c98521c536..21b4d6ab61 100644 --- a/src/lib/helpers/timeConversion.ts +++ b/src/lib/helpers/timeConversion.ts @@ -23,3 +23,24 @@ export function calculateTime(time: number) { return `${years} y`; } } + +export function timeToMinutes(time: number, unit: string) { + switch (unit) { + case 'ms': + return time / 1000 / 60; + case 's': + return time / 60; + case 'm': + return time; + case 'h': + return time * 60; + case 'd': + return time * 60 * 24; + case 'M': + return time * 60 * 24 * 30; + case 'y': + return time * 60 * 24 * 30 * 12; + default: + return time; + } +} diff --git a/src/routes/console/project-[project]/auth/security/+page.svelte b/src/routes/console/project-[project]/auth/security/+page.svelte index 8a59ef5067..61ea95bc32 100644 --- a/src/routes/console/project-[project]/auth/security/+page.svelte +++ b/src/routes/console/project-[project]/auth/security/+page.svelte @@ -10,16 +10,22 @@ import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { trackEvent } from '$lib/actions/analytics'; + import { timeToMinutes } from '$lib/helpers/timeConversion'; const projectId = $project.$id; let isLimited = $project.authLimit === 0 ? 'unlimited' : 'limited'; let newLimit = $project.authLimit === 0 ? 100 : $project.authLimit; + let time: number = $project.authDuration; + let period = 'm'; let btnActive = false; let options = [ - { label: 'years', value: 'years' }, - { label: 'months', value: 'months' }, - { label: 'days', value: 'days' } + { label: 'years', value: 'y' }, + { label: 'months', value: 'M' }, + { label: 'days', value: 'd' }, + { label: 'hours', value: 'h' }, + { label: 'minutes', value: 'm' }, + { label: 'seconds', value: 's' } ]; $: { @@ -56,7 +62,8 @@ } async function updateSessionLength() { try { - //TODO: implement correct SDK call + await sdkForConsole.projects.updateAuthDuration(projectId, timeToMinutes(time, period)); + invalidate(Dependencies.PROJECT); addNotification({ type: 'success', @@ -143,7 +150,7 @@ - Session Length Coming Soon! + Session Length

If you reduce the limit, users who are currently logged in will be logged out of the application. @@ -151,12 +158,12 @@

    - +
From 068c97ecc69b3065f553c135ec6f1697c9d90bbc Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 14 Nov 2022 23:36:56 +0100 Subject: [PATCH 2/6] fix: session lenght inputs --- .../project-[project]/auth/security/+page.svelte | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/routes/console/project-[project]/auth/security/+page.svelte b/src/routes/console/project-[project]/auth/security/+page.svelte index 61ea95bc32..eba52a66cc 100644 --- a/src/routes/console/project-[project]/auth/security/+page.svelte +++ b/src/routes/console/project-[project]/auth/security/+page.svelte @@ -158,20 +158,15 @@
    - - + +