feat: add logout button on navbar

This commit is contained in:
Spectralitree 2021-12-12 08:01:10 +01:00
parent 00c93df585
commit 100ccf2139

View File

@ -1,7 +1,8 @@
<script lang="ts"> <script lang="ts">
import {Navbar, NavbarBrand, Nav, NavItem, NavLink, Collapse, NavbarToggler, Dropdown, DropdownItem, DropdownMenu, DropdownToggle} from 'sveltestrap'; import {Navbar, NavbarBrand, Nav, NavItem, NavLink, Collapse, NavbarToggler, Dropdown, DropdownItem, DropdownMenu, DropdownToggle, Button} from 'sveltestrap';
import { loggedIn } from '../stores'; import { loggedIn } from '../stores';
import { Link } from 'svelte-navigator'; import { Link, navigate } from 'svelte-navigator';
import { get } from 'svelte/store';
export let style: string; export let style: string;
@ -13,6 +14,14 @@
loggedIn.subscribe(value => { loggedIn.subscribe(value => {
loggedIn_value = value; loggedIn_value = value;
}); });
function logout() {
localStorage.removeItem("pk-token");
localStorage.removeItem("pk-user");
loggedIn.update(() => false);
navigate("/");
}
</script> </script>
<div style="background-color: #292929" class="mb-4"> <div style="background-color: #292929" class="mb-4">
<Navbar color="light" light expand="lg"> <Navbar color="light" light expand="lg">
@ -33,6 +42,8 @@
<DropdownMenu end> <DropdownMenu end>
<Link style="text-decoration: none;" to="/dash" state={{tab: "system"}}><DropdownItem>System</DropdownItem></Link> <Link style="text-decoration: none;" to="/dash" state={{tab: "system"}}><DropdownItem>System</DropdownItem></Link>
<Link style="text-decoration: none;" to="/dash" state={{tab: "members"}}><DropdownItem>Members</DropdownItem></Link> <Link style="text-decoration: none;" to="/dash" state={{tab: "members"}}><DropdownItem>Members</DropdownItem></Link>
<DropdownItem divider />
<DropdownItem on:click={logout}>Log out</DropdownItem>
</DropdownMenu> </DropdownMenu>
</Dropdown> </Dropdown>
{/if} {/if}