From 87ad2ac6c724c217d0890de8e7d391cd6fea85cc Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 14 Nov 2023 14:27:42 -0800 Subject: [PATCH] feat: auth header support --- src/lib/components/chat/SettingsModal.svelte | 165 ++++++++++++++++++- src/lib/components/common/Modal.svelte | 2 +- src/routes/+page.svelte | 9 +- 3 files changed, 171 insertions(+), 5 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 3544d91a..80ee7fde 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -4,6 +4,7 @@ import { WEB_UI_VERSION, API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants'; import toast from 'svelte-french-toast'; + import { onMount } from 'svelte'; export let show = false; export let saveSettings: Function; @@ -35,6 +36,11 @@ let gravatarEmail = ''; let OPENAI_API_KEY = ''; + // Auth + let authEnabled = false; + let authType = 'Basic'; + let authContent = ''; + function getGravatarURL(email) { // Trim leading and trailing whitespace from // an email address and force all characters @@ -105,6 +111,10 @@ saveSettings({ speechAutoSend: speechAutoSend }); }; + const toggleAuthHeader = async () => { + authEnabled = !authEnabled; + }; + const pullModelHandler = async () => { const res = await fetch(`${API_BASE_URL}/pull`, { method: 'POST', @@ -228,6 +238,16 @@ gravatarEmail = settings.gravatarEmail ?? ''; OPENAI_API_KEY = settings.OPENAI_API_KEY ?? ''; } + + onMount(() => { + let settings = JSON.parse(localStorage.getItem('settings') ?? '{}'); + + authEnabled = settings.authHeader !== undefined ? true : false; + if (authEnabled) { + authType = settings.authHeader.split(' ')[0]; + authContent = settings.authHeader.split(' ')[1]; + } + }); @@ -358,6 +378,32 @@
Add-ons
+ + -
+
{#if selectedTab === 'general'}
@@ -813,6 +859,123 @@
+
+ +
+ + {:else if selectedTab === 'auth'} +
{ + console.log('auth save'); + saveSettings({ + authHeader: authEnabled ? `${authType} ${authContent}` : undefined + }); + show = false; + }} + > +
+
+
+
Authorization Header
+ + +
+
+ + {#if authEnabled} +
+ +
+
+ + +
+ +
+
+
+ Toggle between 'Basic' + and 'Bearer' by + clicking on the label next to the input. +
+
+ +
+ +
+
Preview Authorization Header
+