aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/logout
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-07-30 09:47:08 -0700
committerAdam Soltys <[email protected]>2022-07-30 09:47:08 -0700
commit8acc59a86b6ec049dfe07f92fd19eeda726136f3 (patch)
tree56c6506d19c38a59fba962c53a71526b3a1825b5 /src/routes/logout
parent1f8b1f52431dc7a95118b310dbca3a178d24614b (diff)
downloadcoinos-ui-8acc59a86b6ec049dfe07f92fd19eeda726136f3.tar.gz
coinos-ui-8acc59a86b6ec049dfe07f92fd19eeda726136f3.zip
logout function
Diffstat (limited to 'src/routes/logout')
-rw-r--r--src/routes/logout/done.svelte13
-rw-r--r--src/routes/logout/index.js26
-rw-r--r--src/routes/logout/index.svelte10
3 files changed, 49 insertions, 0 deletions
diff --git a/src/routes/logout/done.svelte b/src/routes/logout/done.svelte
new file mode 100644
index 00000000..894c7b99
--- /dev/null
+++ b/src/routes/logout/done.svelte
@@ -0,0 +1,13 @@
+<script>
+ import { onMount } from "svelte";
+ import { user, token } from "$lib/store";
+ import { goto } from "$app/navigation";
+ import { close } from "$lib/socket";
+
+ onMount(() => {
+ $token = null;
+ $user = null;
+ close();
+ goto('/');
+ });
+</script>
diff --git a/src/routes/logout/index.js b/src/routes/logout/index.js
new file mode 100644
index 00000000..80e65f8b
--- /dev/null
+++ b/src/routes/logout/index.js
@@ -0,0 +1,26 @@
+import cookie from "cookie";
+
+const opts = {
+ httpOnly: true,
+ sameSite: "lax",
+ path: "/",
+};
+
+export async function GET({ request: { headers } }) {
+ return {
+ status: 302,
+ headers: {
+ location: "/logout/done",
+ "set-cookie": [
+ cookie.serialize("token", "", {
+ ...opts,
+ expires: new Date(0),
+ }),
+ cookie.serialize("refresh_token", "", {
+ ...opts,
+ expires: new Date(0),
+ }),
+ ],
+ },
+ };
+}
diff --git a/src/routes/logout/index.svelte b/src/routes/logout/index.svelte
new file mode 100644
index 00000000..2c6a7085
--- /dev/null
+++ b/src/routes/logout/index.svelte
@@ -0,0 +1,10 @@
+<script>
+ import { onMount } from 'svelte';
+ import { browser } from '$app/env';
+ import { user, token } from '$lib/store';
+
+ onMount(() => {
+ $user = null;
+ $token = null;
+ });
+</script>