From 15e40e47911706bb93c35a06166e699419002281 Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Sat, 9 Apr 2022 11:03:37 +0200
Subject: auto login after registration

---
 web/pw-server/src/routes/register.svelte | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

(limited to 'web/pw-server/src/routes/register.svelte')

diff --git a/web/pw-server/src/routes/register.svelte b/web/pw-server/src/routes/register.svelte
index a303025..f09ccad 100644
--- a/web/pw-server/src/routes/register.svelte
+++ b/web/pw-server/src/routes/register.svelte
@@ -1,4 +1,7 @@
 <script lang="ts">
+  import * as auth from "$lib/auth";
+  import { goto } from "$app/navigation";
+
   let username: string | undefined;
   let password: string | undefined;
 
@@ -26,7 +29,10 @@
       }),
     });
 
-    if (!response.ok) {
+    if (response.ok) {
+      await auth.login({ username, password });
+      goto("/");
+    } else {
       const resp = await response.json();
       const error = resp["error"];
       if (response.status == 422 && error["type"] === "validation_failed") {
-- 
cgit v1.2.3

