Skip to content

Commit

Permalink
api key fields obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed May 12, 2024
1 parent ba688b8 commit 86b3d6e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
64 changes: 64 additions & 0 deletions src/components/InputObfuscated.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

<template>
<div class="wrapper">
<input :type="type" v-model="value" @keyup="onKeyUp" />
<component :is="icon" class="icon" @click="onToggleView" />
</div>
</template>

<script setup>
import { ref, computed } from 'vue'
const type = ref('password')
const value = defineModel()
const emit = defineEmits(['change']);
const icon = computed(() => {
return type.value === 'password' ? 'BIconEye' : 'BIconEyeSlash'
})
const onToggleView = () => {
if (type.value === 'password') {
type.value = 'text'
} else {
type.value = 'password'
}
}
const onKeyUp = (event) => {
emit('change')
}
</script>

<style scoped>
@import '../../css/form.css';
</style>

<style scoped>
.wrapper {
flex: 1;
position: relative;
}
form .group .wrapper input {
width: 100%;
box-sizing: border-box;
padding-left: 6px;
padding-right: 26px;
font-family: monospace;
font-size: calc(var(--form-font-size) - 0.5px) !important;
}
.icon {
cursor: pointer;
position: absolute;
top: 4px;
right: 6px;
}
</style>
3 changes: 2 additions & 1 deletion src/settings/SettingsAnthropic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="group">
<label>API key</label>
<div class="subgroup">
<input type="text" v-model="apiKey" @blur="onKeyChange" /><br />
<InputObfuscated v-model="apiKey" @blur="onKeyChange" /><br />
<a href="https://console.anthropic.com/settings/keys" target="_blank">Get your API key</a>
</div>
</div>
Expand All @@ -25,6 +25,7 @@
import { ref } from 'vue'
import { store } from '../services/store'
import { loadAnthropicModels } from '../services/llm'
import InputObfuscated from '../components/InputObfuscated.vue'
const apiKey = ref(null)
const refreshLabel = ref('Refresh')
Expand Down
3 changes: 2 additions & 1 deletion src/settings/SettingsGroq.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="group">
<label>API key</label>
<div class="subgroup">
<input type="text" v-model="apiKey" @blur="onKeyChange" /><br />
<InputObfuscated v-model="apiKey" @blur="onKeyChange" /><br />
<a href="https://console.groq.com/keys" target="_blank">Get your API key</a>
</div>
</div>
Expand All @@ -25,6 +25,7 @@
import { ref } from 'vue'
import { store } from '../services/store'
import { loadGroqModels } from '../services/llm'
import InputObfuscated from '../components/InputObfuscated.vue'
const apiKey = ref(null)
const refreshLabel = ref('Refresh')
Expand Down
3 changes: 2 additions & 1 deletion src/settings/SettingsMistralAI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="group">
<label>API key</label>
<div class="subgroup">
<input type="text" v-model="apiKey" @blur="onKeyChange" /><br />
<InputObfuscated v-model="apiKey" @blur="onKeyChange" /><br />
<a href="https://console.mistral.ai/api-keys/" target="_blank">Get your API key</a>
</div>
</div>
Expand All @@ -25,6 +25,7 @@
import { ref } from 'vue'
import { store } from '../services/store'
import { loadMistralAIModels } from '../services/llm'
import InputObfuscated from '../components/InputObfuscated.vue'
const apiKey = ref(null)
const refreshLabel = ref('Refresh')
Expand Down
3 changes: 2 additions & 1 deletion src/settings/SettingsOpenAI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="group">
<label>API key</label>
<div class="subgroup">
<input type="text" v-model="apiKey" @blur="onKeyChange" /><br />
<InputObfuscated v-model="apiKey" @blur="onKeyChange" /><br />
<a href="https://platform.openai.com/api-keys" target="_blank">Get your API key</a>
</div>
</div>
Expand Down Expand Up @@ -36,6 +36,7 @@
import { ref } from 'vue'
import { store } from '../services/store'
import { loadOpenAIModels } from '../services/llm'
import InputObfuscated from '../components/InputObfuscated.vue'
const apiKey = ref(null)
const refreshLabel = ref('Refresh')
Expand Down
3 changes: 2 additions & 1 deletion src/settings/SettingsTavily.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="group">
<label>Tavily API Key</label>
<div class="subgroup">
<input type="text" v-model="apiKey" @change="save">
<InputObfuscated v-model="apiKey" @change="save" />
<a href="https://app.tavily.com/home" target="_blank">Get your API key</a>
</div>
</div>
Expand All @@ -23,6 +23,7 @@
import { ref } from 'vue'
import { store } from '../services/store'
import InputObfuscated from '../components/InputObfuscated.vue'
const enabled = ref(false)
const apiKey = ref(null)
Expand Down

0 comments on commit 86b3d6e

Please sign in to comment.