Skip to content

Commit

Permalink
share auth providers UI configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Sep 1, 2022
1 parent f0b57c6 commit f56c52a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 44 deletions.
55 changes: 15 additions & 40 deletions ui/src/components/settings/PageAuthProviders.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SettingsSidebar from "@/components/settings/SettingsSidebar.svelte";
import EmailAuthAccordion from "@/components/settings/EmailAuthAccordion.svelte";
import AuthProviderAccordion from "@/components/settings/AuthProviderAccordion.svelte";
import providersList from "@/providers.js";
$pageTitle = "Auth providers";
Expand Down Expand Up @@ -63,11 +64,10 @@
emailAuth: Object.assign({ enabled: true }, data.emailAuth),
};
const providers = ["googleAuth", "facebookAuth", "githubAuth", "gitlabAuth", "discordAuth"];
for (const provider of providers) {
formSettings[provider] = Object.assign(
for (const providerKey in providersList) {
formSettings[providerKey] = Object.assign(
{ enabled: false, allowRegistrations: true },
data[provider]
data[providerKey]
);
}
Expand Down Expand Up @@ -102,42 +102,17 @@
single
bind:config={formSettings.emailAuth}
/>
<AuthProviderAccordion
single
key="googleAuth"
title="Google"
icon="ri-google-line"
bind:config={formSettings.googleAuth}
/>
<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 Object.entries(providersList) as [key, provider]}
<AuthProviderAccordion
single
{key}
title={provider.title}
icon={provider.icon || "ri-fingerprint-line"}
showSelfHostedFields={provider.selfHosted}
bind:config={formSettings[key]}
/>
{/each}
</div>
<div class="flex m-t-base">
Expand Down
17 changes: 13 additions & 4 deletions ui/src/components/users/ExternalAuthsList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import CommonHelper from "@/utils/CommonHelper";
import { confirm } from "@/stores/confirmation";
import { addSuccessToast } from "@/stores/toasts";
import providersList from "@/providers.js";
const dispatch = createEventDispatcher();
Expand All @@ -12,6 +13,14 @@
let externalAuths = [];
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() {
if (!user?.id) {
externalAuths = [];
Expand All @@ -35,11 +44,11 @@
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
.unlinkExternalAuth(user.id, provider)
.then(() => {
addSuccessToast("Successfully unlinked the provider.");
addSuccessToast(`Successfully unlinked the ${getProviderTitle(provider)} provider.`);
dispatch("unlink", provider);
loadExternalAuths(); // reload list
})
Expand All @@ -62,8 +71,8 @@
<div class="list">
{#each externalAuths as auth}
<div class="list-item">
<i class="ri-{auth.provider}-line" />
<span class="txt">{CommonHelper.sentenize(auth.provider, false)}</span>
<i class={getProviderIcon(auth.provider)} />
<span class="txt">{getProviderTitle(auth.provider)}</span>
<div class="txt-hint">ID: {auth.providerId}</div>
<button
type="button"
Expand Down
31 changes: 31 additions & 0 deletions ui/src/providers.js
Original file line number Diff line number Diff line change
@@ -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",
},
};

0 comments on commit f56c52a

Please sign in to comment.