feat: sessions page

This commit is contained in:
Arman committed 2022-09-05 16:48:25 +02:00
1 parent 23dc0aa158
commit 463cb1ff71
3 files changed
+127 -6

No files matched your search

+3 -2
View File
@@ -86,8 +86,9 @@
showDropdown = false;
newOrgModal.set(true);
}}>New organization</DropListItem>
<DropListLink href={`${base}/console/account`}
>Your Account</DropListLink>
<DropListLink
href={`${base}/console/account`}
on:click={() => (showDropdown = false)}>Your Account</DropListLink>
</ul>
</section>
<section class="drop-section">
@@ -25,10 +25,6 @@
</script>
<Container>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<h2 class="heading-level-5">Activity</h2>
</div>
{#await request}
<div aria-busy="true" />
{:then response}
+124
View File
@@ -0,0 +1,124 @@
<script lang="ts">
import { Empty, Pagination } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Pill } from '$lib/elements';
import {
Table,
TableBody,
TableHeader,
TableRow,
TableCellHead,
TableCell,
TableCellText
} from '$lib/elements/table';
import { Container } from '$lib/layout';
import { sdkForConsole } from '$lib/stores/sdk';
import { pageLimit } from '$lib/stores/layout';
import type { Models } from '@aw-labs/appwrite-console';
let offset = 0;
const getBrowser = (clientCode: string) => {
return sdkForConsole.avatars.getBrowser(clientCode, 40, 40);
};
const logout = (session: Models.Session) => {
sdkForConsole.account.deleteSession(session.$id);
request = sdkForConsole.account.getSessions();
};
const logoutAll = () => {
sdkForConsole.account.deleteSessions();
request = sdkForConsole.account.getSessions();
};
$: request = sdkForConsole.account.getSessions();
</script>
<Container>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<h2 class="heading-level-5">Sessions</h2>
<Button secondary on:click={logoutAll}>
<span class="text">Logout all sessions</span>
</Button>
</div>
{#await request}
<div aria-busy="true" />
{:then response}
{#if response.total}
<Table>
<TableHeader>
<TableCellHead>Client</TableCellHead>
<TableCellHead width={100}>Location</TableCellHead>
<TableCellHead width={150}>IP</TableCellHead>
<TableCellHead width={100} />
</TableHeader>
<TableBody>
{#each response.sessions as session}
<TableRow>
<TableCell title="Client">
<div class="u-flex u-gap-12">
<div class="u-flex u-cross-center u-gap-12">
{#if session.clientName}
<div class="avatar is-small">
<img
height="20"
width="20"
src={getBrowser(session.clientCode).toString()}
alt={session.clientName} />
</div>
<p class="text u-trim">
{session.clientName}
{session.clientVersion}
on {session.osName}
{session.osVersion}
</p>
{:else}
<span class="avatar is-color-empty" />
<p class="text u-trim">Unknown</p>
{/if}
</div>
<Pill>{session.provider}</Pill>
{#if session.current}
<Pill success>current session</Pill>
{/if}
</div>
</TableCell>
<TableCellText title="Location">
{#if session.countryCode !== '--'}
{session.countryName}
{:else}
Unknown
{/if}
</TableCellText>
<TableCellText title="IP">{session.ip}</TableCellText>
<TableCell title="Client">
<Button secondary on:click={() => logout(session)}>Logout</Button>
</TableCell>
</TableRow>
{/each}
</TableBody>
</Table>
{:else}
<Empty centered>
<div class="u-flex u-flex-vertical u-cross-center">
<div class="common-section">
<p>No sessions available</p>
</div>
<div class="common-section">
<Button
external
secondary
href="https://appwrite.io/docs/server/authentication?sdk=nodejs-default#usersGetsessions"
>Documentation</Button>
</div>
</div>
</Empty>
{/if}
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {response.total}</p>
<Pagination limit={$pageLimit} bind:offset sum={response.total} />
</div>
{/await}
</Container>