diff --git a/package-lock.json b/package-lock.json index 330a768fc1..46f6edbdd9 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": "^13.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": "13.0.0", + "resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-13.0.0.tgz", + "integrity": "sha512-a5illDoFZAhgLP8Ae+KHPzBIUozKXzjyHUw6jTwNPZaL+b2RnTe3oRLZU8l8Kt5pB5m7NZx6kAcZm+NMf8NeCw==", "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": "13.0.0", + "resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-13.0.0.tgz", + "integrity": "sha512-a5illDoFZAhgLP8Ae+KHPzBIUozKXzjyHUw6jTwNPZaL+b2RnTe3oRLZU8l8Kt5pB5m7NZx6kAcZm+NMf8NeCw==", "requires": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" diff --git a/package.json b/package.json index e20a05bdae..cbd2c487c4 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": "^13.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..da5861cac8 100644 --- a/src/lib/helpers/timeConversion.ts +++ b/src/lib/helpers/timeConversion.ts @@ -23,3 +23,44 @@ export function calculateTime(time: number) { return `${years} y`; } } + +export function timeToSeconds(time: number, unit: string) { + switch (unit) { + case 'ms': + return time / 1000; + case 's': + return time; + case 'm': + return time * 60; + case 'h': + return time * 60 * 60; + case 'd': + return time * 60 * 60 * 24; + case 'M': + return time * 60 * 60 * 24 * 30; + case 'y': + return time * 60 * 60 * 24 * 30 * 12; + default: + return time; + } +} +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/lib/stores/app.ts b/src/lib/stores/app.ts index ded47a8d5e..80d7e52bd3 100644 --- a/src/lib/stores/app.ts +++ b/src/lib/stores/app.ts @@ -23,7 +23,7 @@ function createFeedbackStore() { elapsed: browser ? parseInt(localStorage.getItem('feedbackElapsed')) : 0, visualized: browser ? parseInt(localStorage.getItem('feedbackVisualized')) : 0, notification: false, - type: 'nps' + type: 'general' }); return { subscribe, diff --git a/src/routes/console/project-[project]/auth/security/+page.svelte b/src/routes/console/project-[project]/auth/security/+page.svelte index 8a59ef5067..5392e0db57 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 { timeToSeconds } from '$lib/helpers/timeConversion'; + import { writable } from 'svelte/store'; const projectId = $project.$id; let isLimited = $project.authLimit === 0 ? 'unlimited' : 'limited'; let newLimit = $project.authLimit === 0 ? 100 : $project.authLimit; + let time = $project.authDuration; + let timeInSec = time; + let period = writable('s'); let btnActive = false; let options = [ - { label: 'years', value: 'years' }, - { label: 'months', value: 'months' }, - { label: 'days', value: 'days' } + { label: 'days', value: 'd' }, + { label: 'hours', value: 'h' }, + { label: 'minutes', value: 'm' }, + { label: 'seconds', value: 's' } ]; $: { @@ -56,7 +62,12 @@ } async function updateSessionLength() { try { - //TODO: implement correct SDK call + await sdkForConsole.projects.updateAuthDuration( + projectId, + timeToSeconds(time, $period) + ); + invalidate(Dependencies.PROJECT); + $period = 's'; addNotification({ type: 'success', @@ -70,6 +81,26 @@ }); } } + + period.subscribe((p) => { + if (p === 'd') { + time = timeInSec / 86400; + timeInSec = timeToSeconds(time, p); + } else if (p === 'h') { + time = timeInSec / 3600; + timeInSec = timeToSeconds(time, p); + } else if (p === 'm') { + time = timeInSec / 60; + timeInSec = timeToSeconds(time, p); + } else if (p === 's') { + time = timeInSec; + timeInSec = timeToSeconds(time, p); + } + }); + + $: if (time) { + timeInSec = timeToSeconds(time, $period); + } @@ -143,7 +174,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,20 +182,15 @@

    - - + +