2022-04-28 03:11:44 -07:00
|
|
|
<template>
|
|
|
|
<SettingsView>
|
|
|
|
<div :class="$style.container">
|
|
|
|
<div :class="$style.header">
|
|
|
|
<n8n-heading size="2xlarge">
|
|
|
|
{{ $locale.baseText('settings.api') }}
|
|
|
|
</n8n-heading>
|
|
|
|
</div>
|
2022-04-28 06:57:49 -07:00
|
|
|
|
|
|
|
<div v-if="apiKey">
|
|
|
|
<p class="mb-s">
|
|
|
|
<n8n-text color="text-base">
|
|
|
|
<font-awesome-icon icon="info-circle" />
|
|
|
|
{{ $locale.baseText('settings.api.view.info') }}
|
|
|
|
<n8n-link to="https://docs.n8n.io/api/">
|
|
|
|
{{ $locale.baseText('generic.learnMore') }}
|
|
|
|
</n8n-link>
|
|
|
|
</n8n-text>
|
|
|
|
</p>
|
|
|
|
<n8n-card :class="$style.card">
|
|
|
|
<span :class="$style.delete">
|
|
|
|
<n8n-link @click="showDeleteModal">
|
|
|
|
{{ $locale.baseText('generic.delete') }}
|
|
|
|
</n8n-link>
|
|
|
|
</span>
|
|
|
|
<CopyInput
|
|
|
|
:label="$locale.baseText('settings.api.view.myKey')"
|
|
|
|
:value="apiKey"
|
|
|
|
:toast-title="$locale.baseText('settings.api.view.copy.toast')"
|
|
|
|
/>
|
|
|
|
</n8n-card>
|
|
|
|
</div>
|
2022-04-28 03:11:44 -07:00
|
|
|
<div :class="$style.placeholder" v-else>
|
|
|
|
<n8n-heading size="xlarge">
|
|
|
|
{{ $locale.baseText('settings.api.create.title') }}
|
|
|
|
</n8n-heading>
|
|
|
|
<p class="mt-2xs mb-l">
|
2022-04-28 06:57:49 -07:00
|
|
|
<n8n-text color="text-base">
|
|
|
|
{{$locale.baseText('settings.api.create.description')}}
|
|
|
|
<n8n-link to="https://docs.n8n.io/api/">
|
|
|
|
{{$locale.baseText('settings.api.create.description.link')}}
|
|
|
|
</n8n-link>
|
|
|
|
</n8n-text>
|
2022-04-28 03:11:44 -07:00
|
|
|
</p>
|
|
|
|
<n8n-button :loading="loading" size="large" class="mt-l" @click="createApiKey">
|
|
|
|
{{$locale.baseText(loading ? 'settings.api.create.button.loading' : 'settings.api.create.button')}}
|
|
|
|
</n8n-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</SettingsView>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {createApiKey, deleteApiKey, getApiKey } from '../api/api-keys';
|
|
|
|
import { showMessage } from '@/components/mixins/showMessage';
|
|
|
|
import { IUser } from '@/Interface';
|
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
|
|
|
|
import SettingsView from './SettingsView.vue';
|
2022-04-28 06:57:49 -07:00
|
|
|
import CopyInput from '../components/CopyInput.vue';
|
|
|
|
import {DELETE_API_KEY_MODAL_KEY} from "../constants";
|
2022-04-28 03:11:44 -07:00
|
|
|
|
|
|
|
export default mixins(
|
|
|
|
showMessage,
|
|
|
|
).extend({
|
|
|
|
name: 'SettingsPersonalView',
|
|
|
|
components: {
|
|
|
|
SettingsView,
|
2022-04-28 06:57:49 -07:00
|
|
|
CopyInput,
|
2022-04-28 03:11:44 -07:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: false,
|
|
|
|
mounted: false,
|
|
|
|
error: '',
|
|
|
|
};
|
|
|
|
},
|
2022-04-28 06:57:49 -07:00
|
|
|
mounted() {
|
2022-04-28 03:11:44 -07:00
|
|
|
this.getApiKey();
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
currentUser() {
|
|
|
|
return this.$store.getters['users/currentUser'] as IUser;
|
|
|
|
},
|
2022-04-28 06:57:49 -07:00
|
|
|
apiKey() {
|
|
|
|
return this.$store.getters['settings/apiKey'];
|
|
|
|
},
|
2022-04-28 03:11:44 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2022-04-28 06:57:49 -07:00
|
|
|
showDeleteModal() {
|
|
|
|
this.$store.dispatch('ui/openModal', DELETE_API_KEY_MODAL_KEY);
|
|
|
|
},
|
2022-04-28 03:11:44 -07:00
|
|
|
async getApiKey() {
|
|
|
|
try {
|
2022-04-28 06:57:49 -07:00
|
|
|
this.$store.dispatch('settings/getApiKey');
|
2022-04-28 03:11:44 -07:00
|
|
|
} catch (error) {
|
2022-04-28 06:57:49 -07:00
|
|
|
this.$showError(error, this.$locale.baseText('settings.api.view.error'));
|
2022-04-28 03:11:44 -07:00
|
|
|
} finally {
|
|
|
|
this.mounted = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async createApiKey() {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
try {
|
2022-04-28 06:57:49 -07:00
|
|
|
this.$store.dispatch('settings/createApiKey');
|
2022-04-28 03:11:44 -07:00
|
|
|
} catch (error) {
|
2022-04-28 06:57:49 -07:00
|
|
|
this.$showError(error, this.$locale.baseText('settings.api.create.error'));
|
2022-04-28 03:11:44 -07:00
|
|
|
} finally {
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.container {
|
|
|
|
> * {
|
|
|
|
margin-bottom: var(--spacing-2xl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
|
|
*:first-child {
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.placeholder {
|
|
|
|
border-radius: var(--border-radius-xlarge);
|
|
|
|
border: 2px dashed var(--color-foreground-light);
|
|
|
|
height: 245px;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
2022-04-28 06:57:49 -07:00
|
|
|
|
|
|
|
.card {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.delete {
|
|
|
|
position: absolute;
|
|
|
|
display: inline-block;
|
|
|
|
top: var(--spacing-s);
|
|
|
|
right: var(--spacing-s);
|
|
|
|
}
|
2022-04-28 03:11:44 -07:00
|
|
|
</style>
|
|
|
|
|