share auth providers UI configurations
This commit is contained in:
parent
f0b57c6b91
commit
f56c52a1f7
|
@ -8,6 +8,7 @@
|
||||||
import SettingsSidebar from "@/components/settings/SettingsSidebar.svelte";
|
import SettingsSidebar from "@/components/settings/SettingsSidebar.svelte";
|
||||||
import EmailAuthAccordion from "@/components/settings/EmailAuthAccordion.svelte";
|
import EmailAuthAccordion from "@/components/settings/EmailAuthAccordion.svelte";
|
||||||
import AuthProviderAccordion from "@/components/settings/AuthProviderAccordion.svelte";
|
import AuthProviderAccordion from "@/components/settings/AuthProviderAccordion.svelte";
|
||||||
|
import providersList from "@/providers.js";
|
||||||
|
|
||||||
$pageTitle = "Auth providers";
|
$pageTitle = "Auth providers";
|
||||||
|
|
||||||
|
@ -63,11 +64,10 @@
|
||||||
emailAuth: Object.assign({ enabled: true }, data.emailAuth),
|
emailAuth: Object.assign({ enabled: true }, data.emailAuth),
|
||||||
};
|
};
|
||||||
|
|
||||||
const providers = ["googleAuth", "facebookAuth", "githubAuth", "gitlabAuth", "discordAuth"];
|
for (const providerKey in providersList) {
|
||||||
for (const provider of providers) {
|
formSettings[providerKey] = Object.assign(
|
||||||
formSettings[provider] = Object.assign(
|
|
||||||
{ enabled: false, allowRegistrations: true },
|
{ enabled: false, allowRegistrations: true },
|
||||||
data[provider]
|
data[providerKey]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,42 +102,17 @@
|
||||||
single
|
single
|
||||||
bind:config={formSettings.emailAuth}
|
bind:config={formSettings.emailAuth}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{#each Object.entries(providersList) as [key, provider]}
|
||||||
<AuthProviderAccordion
|
<AuthProviderAccordion
|
||||||
single
|
single
|
||||||
key="googleAuth"
|
{key}
|
||||||
title="Google"
|
title={provider.title}
|
||||||
icon="ri-google-line"
|
icon={provider.icon || "ri-fingerprint-line"}
|
||||||
bind:config={formSettings.googleAuth}
|
showSelfHostedFields={provider.selfHosted}
|
||||||
/>
|
bind:config={formSettings[key]}
|
||||||
<AuthProviderAccordion
|
|
||||||
single
|
|
||||||
key="facebookAuth"
|
|
||||||
title="Facebook"
|
|
||||||
icon="ri-facebook-line"
|
|
||||||
bind:config={formSettings.facebookAuth}
|
|
||||||
/>
|
|
||||||
<AuthProviderAccordion
|
|
||||||
single
|
|
||||||
key="githubAuth"
|
|
||||||
title="GitHub"
|
|
||||||
icon="ri-github-line"
|
|
||||||
bind:config={formSettings.githubAuth}
|
|
||||||
/>
|
|
||||||
<AuthProviderAccordion
|
|
||||||
single
|
|
||||||
key="gitlabAuth"
|
|
||||||
title="GitLab"
|
|
||||||
icon="ri-gitlab-line"
|
|
||||||
showSelfHostedFields
|
|
||||||
bind:config={formSettings.gitlabAuth}
|
|
||||||
/>
|
|
||||||
<AuthProviderAccordion
|
|
||||||
single
|
|
||||||
key="discordAuth"
|
|
||||||
title="Discord"
|
|
||||||
icon="ri-discord-line"
|
|
||||||
bind:config={formSettings.discordAuth}
|
|
||||||
/>
|
/>
|
||||||
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex m-t-base">
|
<div class="flex m-t-base">
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import CommonHelper from "@/utils/CommonHelper";
|
import CommonHelper from "@/utils/CommonHelper";
|
||||||
import { confirm } from "@/stores/confirmation";
|
import { confirm } from "@/stores/confirmation";
|
||||||
import { addSuccessToast } from "@/stores/toasts";
|
import { addSuccessToast } from "@/stores/toasts";
|
||||||
|
import providersList from "@/providers.js";
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
@ -12,6 +13,14 @@
|
||||||
let externalAuths = [];
|
let externalAuths = [];
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
||||||
|
function getProviderTitle(provider) {
|
||||||
|
return providersList[provider + "Auth"]?.title || CommonHelper.sentenize(auth.provider, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProviderIcon(provider) {
|
||||||
|
return providersList[provider + "Auth"]?.icon || `ri-${provider}-line`;
|
||||||
|
}
|
||||||
|
|
||||||
async function loadExternalAuths() {
|
async function loadExternalAuths() {
|
||||||
if (!user?.id) {
|
if (!user?.id) {
|
||||||
externalAuths = [];
|
externalAuths = [];
|
||||||
|
@ -35,11 +44,11 @@
|
||||||
return; // nothing to unlink
|
return; // nothing to unlink
|
||||||
}
|
}
|
||||||
|
|
||||||
confirm(`Do you really want to unlink the selected provider?`, () => {
|
confirm(`Do you really want to unlink the ${getProviderTitle(provider)} provider?`, () => {
|
||||||
return ApiClient.users
|
return ApiClient.users
|
||||||
.unlinkExternalAuth(user.id, provider)
|
.unlinkExternalAuth(user.id, provider)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
addSuccessToast("Successfully unlinked the provider.");
|
addSuccessToast(`Successfully unlinked the ${getProviderTitle(provider)} provider.`);
|
||||||
dispatch("unlink", provider);
|
dispatch("unlink", provider);
|
||||||
loadExternalAuths(); // reload list
|
loadExternalAuths(); // reload list
|
||||||
})
|
})
|
||||||
|
@ -62,8 +71,8 @@
|
||||||
<div class="list">
|
<div class="list">
|
||||||
{#each externalAuths as auth}
|
{#each externalAuths as auth}
|
||||||
<div class="list-item">
|
<div class="list-item">
|
||||||
<i class="ri-{auth.provider}-line" />
|
<i class={getProviderIcon(auth.provider)} />
|
||||||
<span class="txt">{CommonHelper.sentenize(auth.provider, false)}</span>
|
<span class="txt">{getProviderTitle(auth.provider)}</span>
|
||||||
<div class="txt-hint">ID: {auth.providerId}</div>
|
<div class="txt-hint">ID: {auth.providerId}</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Object list with all supported OAuth2 providers in the format:
|
||||||
|
// ```
|
||||||
|
// { settingsKey: { title, icon, selfHosted } }
|
||||||
|
// ```
|
||||||
|
export default {
|
||||||
|
googleAuth: {
|
||||||
|
title: "Google",
|
||||||
|
icon: "ri-google-line",
|
||||||
|
},
|
||||||
|
facebookAuth: {
|
||||||
|
title: "Facebook",
|
||||||
|
icon: "ri-facebook-line",
|
||||||
|
},
|
||||||
|
twitterAuth: {
|
||||||
|
title: "Twitter",
|
||||||
|
icon: "ri-twitter-line",
|
||||||
|
},
|
||||||
|
githubAuth: {
|
||||||
|
title: "GitHub",
|
||||||
|
icon: "ri-github-line",
|
||||||
|
},
|
||||||
|
gitlabAuth: {
|
||||||
|
title: "GitLab",
|
||||||
|
icon: "ri-gitlab-line",
|
||||||
|
selfHosted: true,
|
||||||
|
},
|
||||||
|
discordAuth: {
|
||||||
|
title: "Discord",
|
||||||
|
icon: "ri-discord-line",
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue