feat: move log out button to settings

This commit is contained in:
Sam 2023-03-14 15:17:24 +01:00
parent e3f3ac1d8d
commit 1e6eb66168
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
4 changed files with 22 additions and 20 deletions

View File

@ -1,14 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { userStore } from "$lib/store";
import { onMount } from "svelte";
onMount(() => {
userStore.set(null);
localStorage.removeItem("pronouns-token");
localStorage.removeItem("pronouns-user");
goto("/");
});
</script>
<h1>Log out</h1>

View File

@ -1 +0,0 @@
export const ssr = false;

View File

@ -85,9 +85,6 @@
<NavItem>
<NavLink href="/settings">Settings</NavLink>
</NavItem>
<NavItem>
<NavLink href="/auth/logout">Log out</NavLink>
</NavItem>
{:else}
<NavItem>
<NavLink href="/auth/login">Log in</NavLink>

View File

@ -1,10 +1,22 @@
<script lang="ts">
import { page } from "$app/stores";
import type { LayoutData } from "./$types";
import { ListGroup, ListGroupItem } from "sveltestrap";
import { Button, ListGroup, ListGroupItem, Modal, ModalBody, ModalFooter } from "sveltestrap";
import { userStore } from "$lib/store";
import { goto } from "$app/navigation";
export let data: LayoutData;
let isOpen = false;
const toggle = () => (isOpen = !isOpen);
const logOut = () => {
userStore.set(null);
localStorage.removeItem("pronouns-token");
localStorage.removeItem("pronouns-user");
toggle();
goto("/");
};
</script>
<div class="grid">
@ -39,10 +51,18 @@
>
Data export
</ListGroupItem>
<ListGroupItem tag="button" on:click={toggle}>Log out</ListGroupItem>
</ListGroup>
</div>
<div class="col-md m-3">
<slot />
</div>
</div>
<Modal header="Log out" {isOpen} {toggle}>
<ModalBody>Are you sure you want to log out?</ModalBody>
<ModalFooter>
<Button color="primary" on:click={logOut}>Log out</Button>
<Button color="secondary" on:click={toggle}>Cancel</Button>
</ModalFooter>
</Modal>
</div>