Skip to content

Commit

Permalink
Sveltekit now can create cookies (Fixed problem with cookies).
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysilelek committed Nov 16, 2023
1 parent 0080ab6 commit ddc191f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
File renamed without changes.
12 changes: 10 additions & 2 deletions client/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<script>
export let data;
</script>

<h1>Welcome to Local Bargains</h1>
<a href="/auth/register"> Sign up </a>
<a href="/auth/login"> Sign in </a>
{#if data.accessToken}
{data.accessToken}
{:else}
<a href="/auth/register"> Sign up </a>
<a href="/auth/login"> Sign in </a>
{/if}

<slot />
3 changes: 0 additions & 3 deletions client/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<script>
</script>

<svelte:head>
<title>Local Bargains!</title>
</svelte:head>
Expand Down
8 changes: 6 additions & 2 deletions client/src/routes/auth/login/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fail, redirect } from '@sveltejs/kit';
import * as set_cookie_parser from 'set-cookie-parser';

export const actions = {
form: async ({ request, url, cookies }) => {
Expand Down Expand Up @@ -34,8 +35,11 @@ export const actions = {
message: 'Bad password!'
});
}
console.log(response);
console.log(cookies.getAll());
const { headers } = response;
for (const str of set_cookie_parser.splitCookiesString(headers.get('set-cookie'))) {
const { name, value, ...options } = set_cookie_parser.parseString(str);
cookies.set(name, value, { ...options });
}
throw redirect(303, url.searchParams.get('redirectTo') || '/');
}
}

0 comments on commit ddc191f

Please sign in to comment.