Skip to content

Commit

Permalink
Fix sign out
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Oct 31, 2023
1 parent 924548d commit fb8e4a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import '../global.sass';
import * as cookie from 'cookie';
const socialLinks = [
{ name: 'Facebook', url: 'https://www.facebook.com/' },
{ name: 'Twitter', url: 'https://twitter.com/' },
{ name: 'Instagram', url: 'https://www.instagram.com/' },
{ name: 'LinkedIn', url: 'https://www.linkedin.com/' }
];
const signOut = async () => {
await goto('/');
};
</script>

<header>
Expand All @@ -24,6 +29,11 @@
<nav>
<ul>
<li><a href="/home">Home</a></li>
<li>
<form method="POST" action="/">
<button on:click={signOut} type="submit">Sign out</button>
</form>
</li>
</ul>
</nav>
{/if}
Expand Down Expand Up @@ -82,6 +92,11 @@
cursor: pointer
ul
display: flex
flex-direction: row
gap: 2rem
align-items: center
li
list-style: none
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';

export const prerender = true;
import type { Actions } from '@sveltejs/kit';

export const load: PageServerLoad = async ({ cookies }) => {
const jwt = cookies.get('sessionjwt');
Expand All @@ -10,3 +9,9 @@ export const load: PageServerLoad = async ({ cookies }) => {
throw redirect(307, '/home');
}
};

export const actions = {
default: async ({ cookies }) => {
cookies.delete('sessionjwt');
}
} satisfies Actions;

0 comments on commit fb8e4a3

Please sign in to comment.