From 2479d1ec1a10410a72b2744f4067927112590f2a Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Thu, 24 Mar 2022 20:43:27 +0100
Subject: don't show save button when user is not logged in

---
 web/pw-server/src/lib/components/SubmitPane.svelte | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

(limited to 'web/pw-server/src/lib/components/SubmitPane.svelte')

diff --git a/web/pw-server/src/lib/components/SubmitPane.svelte b/web/pw-server/src/lib/components/SubmitPane.svelte
index 497f3ce..919f578 100644
--- a/web/pw-server/src/lib/components/SubmitPane.svelte
+++ b/web/pw-server/src/lib/components/SubmitPane.svelte
@@ -1,5 +1,8 @@
 <script lang="ts">
-  import { createEventDispatcher, onMount } from "svelte";
+import { get_session_token } from "$lib/auth";
+
+  import { currentUser } from "$lib/stores/current_user";
+import { createEventDispatcher, onMount } from "svelte";
   import Select from "svelte-select";
 
   export let editSession;
@@ -54,6 +57,7 @@
       method: "POST",
       headers: {
         "Content-Type": "application/json",
+        "Authorization": `Bearer ${get_session_token()}`,
       },
       body: JSON.stringify({
         bot_name: botName,
@@ -94,12 +98,16 @@
   </div>
   <div class="save-form">
     <h4>Save your bot</h4>
-    <div>Add your bot to the opponents list</div>
-    <input type="text" class="bot-name-input" placeholder="bot name" bind:value={botName} />
-    {#if saveErrorText}
-      <div class="error-text">{saveErrorText}</div>
+    {#if $currentUser}
+      <div>Add your bot to the opponents list</div>
+      <input type="text" class="bot-name-input" placeholder="bot name" bind:value={botName} />
+      {#if saveErrorText}
+        <div class="error-text">{saveErrorText}</div>
+      {/if}
+      <button class="submit-button save-button" on:click={saveBot}>Save</button>
+    {:else}
+      Sign in to add your bot to the opponents list.
     {/if}
-    <button class="submit-button save-button" on:click={saveBot}>Save</button>
   </div>
 </div>
 
-- 
cgit v1.2.3

