From d17a806783758fc1ecc55486bedc9f5db6bc78f5 Mon Sep 17 00:00:00 2001 From: Roman Godmaire Date: Sun, 19 Nov 2023 08:24:24 -0500 Subject: [PATCH] feat: Signout Button --- src/routes/account/+page.server.ts | 23 ++++++ src/routes/account/+page.svelte | 119 +++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 src/routes/account/+page.server.ts create mode 100644 src/routes/account/+page.svelte diff --git a/src/routes/account/+page.server.ts b/src/routes/account/+page.server.ts new file mode 100644 index 0000000..5f1050b --- /dev/null +++ b/src/routes/account/+page.server.ts @@ -0,0 +1,23 @@ +import { fail, redirect } from '@sveltejs/kit'; + +import type { Actions, PageServerLoad } from './$types'; + +export const load: PageServerLoad = async ({ locals: { authReq } }) => { + const session = await authReq.validate(); + if (!session) throw redirect(302, '/login'); + return { + username: session.user.username + }; +}; + +export const actions: Actions = { + signout: async ({ locals: { auth, authReq } }) => { + const session = await authReq.validate(); + if (!session) return fail(401); + + await auth.invalidateSession(session.sessionId); + authReq.setSession(null); // remove cookie + + throw redirect(302, '/login'); + } +}; diff --git a/src/routes/account/+page.svelte b/src/routes/account/+page.svelte new file mode 100644 index 0000000..5484b3d --- /dev/null +++ b/src/routes/account/+page.svelte @@ -0,0 +1,119 @@ + + + + Account | Roll With It + + +
+

Account

+
+
+ {#if form?.type === 'updateAccount'} + {form?.message} + {/if} + + + +
+ + +
+
+ +
+
+ {#if form?.type === 'changePassword'} + {form.message} + {/if} + + +
+ + +
+ + +
+
+ +
+
+

Billing Information

+

Thank you for your support!

+
+
+ +
+ +
+