From ce3b8aacf73b841887f3eec631851d086a7578f1 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:21:57 +0200 Subject: [chore] Warn about email/password change when using OIDC (#2975) * [chore] Warn about email/password change when using OIDC * go fmt --- web/source/settings/lib/types/instance.ts | 1 + web/source/settings/views/user/settings.tsx | 72 ++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 7 deletions(-) (limited to 'web/source') diff --git a/web/source/settings/lib/types/instance.ts b/web/source/settings/lib/types/instance.ts index 4c6f5061b..11f75032c 100644 --- a/web/source/settings/lib/types/instance.ts +++ b/web/source/settings/lib/types/instance.ts @@ -49,6 +49,7 @@ export interface InstanceConfiguration { polls: InstancePolls; accounts: InstanceAccounts; emojis: InstanceEmojis; + oidc_enabled?: boolean; } export interface InstanceAccounts { diff --git a/web/source/settings/views/user/settings.tsx b/web/source/settings/views/user/settings.tsx index a27cc1ba3..5696144a0 100644 --- a/web/source/settings/views/user/settings.tsx +++ b/web/source/settings/views/user/settings.tsx @@ -28,6 +28,7 @@ import { useVerifyCredentialsQuery } from "../../lib/query/oauth"; import { useEmailChangeMutation, usePasswordChangeMutation, useUpdateCredentialsMutation, useUserQuery } from "../../lib/query/user"; import Loading from "../../components/loading"; import { User } from "../../lib/types/user"; +import { useInstanceV1Query } from "../../lib/query/gts-api"; export default function UserSettings() { return ( @@ -106,6 +107,24 @@ function UserSettingsForm({ data }) { } function PasswordChange() { + // Load instance data. + const { + data: instance, + isFetching: isFetchingInstance, + isLoading: isLoadingInstance + } = useInstanceV1Query(); + if (isFetchingInstance || isLoadingInstance) { + return ; + } + + if (instance === undefined) { + throw "could not fetch instance"; + } + + return ; +} + +function PasswordChangeForm({ oidcEnabled }: { oidcEnabled?: boolean }) { const form = { oldPassword: useTextInput("old_password"), newPassword: useTextInput("new_password", { @@ -133,6 +152,13 @@ function PasswordChange() {

Change Password

+ { oidcEnabled &&

+ This instance is running with OIDC as its authorization + identity provider. +
+ This means you cannot change your password using this settings panel. +
+ To change your password, you should instead contact your OIDC provider. +

}
+ ); } function EmailChange() { - // Load existing user data. - const { data: user, isFetching, isLoading } = useUserQuery(); - if (isFetching || isLoading) { + // Load instance data. + const { + data: instance, + isFetching: isFetchingInstance, + isLoading: isLoadingInstance + } = useInstanceV1Query(); + + // Load user data. + const { + data: user, + isFetching: isFetchingUser, + isLoading: isLoadingUser + } = useUserQuery(); + + if ( + (isFetchingInstance || isLoadingInstance) || + (isFetchingUser || isLoadingUser) + ) { return ; } @@ -183,10 +228,14 @@ function EmailChange() { throw "could not fetch user"; } - return ; + if (instance === undefined) { + throw "could not fetch instance"; + } + + return ; } -function EmailChangeForm({user}: {user: User}) { +function EmailChangeForm({user, oidcEnabled}: { user: User, oidcEnabled?: boolean }) { const form = { currentEmail: useTextInput("current_email", { defaultValue: user.email, @@ -217,6 +266,15 @@ function EmailChangeForm({user}: {user: User}) {

Change Email

+ { oidcEnabled &&

+ This instance is running with OIDC as its authorization + identity provider. +
+ You can still change your email address using this settings panel, + but it will only affect which address GoToSocial uses to contact you, + not the email address you use to log in. +
+ To change the email address you use to log in, contact your OIDC provider. +

}
- { user.unconfirmed_email && <> + { (user.unconfirmed_email && user.unconfirmed_email !== user.email) && <>
-- cgit v1.2.3