A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(app): pick the authorizing account inside the OAuth flow
Hampusa0d95f24954d
diff --git a/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.module.css b/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.module.cssindex bb385ed96..a4e9c3c7d 100644--- a/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.module.css+++ b/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.module.css@@ -76,12 +76,6 @@gap: 0.75rem;}-.accountList {- display: flex;- flex-direction: column;- gap: 0.45rem;-}-.sectionDivider {height: 0.0625rem;width: 100%;@@ -334,7 +328,7 @@}.guildOptionNotice {- margin-left: auto;+ margin-inline-start: auto;color: var(--text-tertiary);font-size: 0.85rem;}@@ -351,7 +345,7 @@font-size: 0.85rem;color: var(--text-secondary);line-height: 1.35;- text-align: left;+ text-align: start;display: block;width: 100%;margin-top: 0.35rem;@@ -369,3 +363,32 @@flex: 1;width: 100%;}++.authorizingAccount {+ display: flex;+ align-items: center;+ justify-content: center;+ gap: var(--spacing-2);+ max-width: 100%;+ margin-top: var(--spacing-1);+ color: var(--text-secondary);+ font-size: 0.875rem;+ line-height: 1.25rem;+}++.authorizingAccountAvatar {+ display: flex;+ flex-shrink: 0;+}++.authorizingAccountText {+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++.authorizingAccountText strong {+ color: var(--text-primary);+ font-weight: 600;+}diff --git a/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.tsx b/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.tsxindex a55b543b0..a95e0f0fa 100644--- a/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.tsx+++ b/fluxer_app/src/features/auth/components/pages/OAuthAuthorizePage.tsx@@ -10,14 +10,45 @@ import {useFluxerDocumentTitle} from '@app/features/window/hooks/useFluxerDocumeimport {useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';import type React from 'react';+import {useCallback, useState} from 'react';++interface OAuthAuthorizeSessionProps {+ readonly startAtConsent: boolean;+ readonly onAccountChanged: () => void;+}++const OAuthAuthorizeSession = observer(function OAuthAuthorizeSession({+ startAtConsent,+ onAccountChanged,+}: OAuthAuthorizeSessionProps): React.ReactElement {+ const flow = useAuthorizeFlow({startAtConsent});+ const choosingAccount =+ flow.phase.kind === 'session_expired' || (flow.phase.kind === 'review' && flow.phase.step === 'account');+ useAuthPresentation({variant: choosingAccount ? 'standard' : 'compact'});+ return (+ <OAuthAuthorizeFlowPanel+ flow={flow}+ onAccountChanged={onAccountChanged}+ data-flx="auth.o-auth-authorize-page.o-auth-authorize-flow-panel"+ />+ );+});const OAuthAuthorizePage: React.FC = observer(() => {const {i18n} = useLingui();useFluxerDocumentTitle(i18n._(AUTHORIZE_APPLICATION_DESCRIPTOR));- const flow = useAuthorizeFlow();- const cardVariant = flow.phase.kind === 'review' && flow.phase.step === 'account' ? 'standard' : 'compact';- useAuthPresentation({variant: cardVariant});- return <OAuthAuthorizeFlowPanel flow={flow} data-flx="auth.o-auth-authorize-page.o-auth-authorize-flow-panel" />;+ const [accountGeneration, setAccountGeneration] = useState(0);+ const handleAccountChanged = useCallback(() => {+ setAccountGeneration((generation) => generation + 1);+ }, []);+ return (+ <OAuthAuthorizeSession+ key={accountGeneration}+ startAtConsent={accountGeneration > 0}+ onAccountChanged={handleAccountChanged}+ data-flx="auth.o-auth-authorize-page.o-auth-authorize-session"+ />+ );});export default OAuthAuthorizePage;diff --git a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAccountStep.tsx b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAccountStep.tsxindex 7abe2f564..cda5784bd 100644--- a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAccountStep.tsx+++ b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAccountStep.tsx@@ -1,20 +1,36 @@// SPDX-License-Identifier: AGPL-3.0-or-later-import {openAccountSwitcherModal} from '@app/features/auth/commands/AccountSwitcherModalCommands';-import {AccountRow} from '@app/features/auth/components/accounts/AccountRow';+import {Routes} from '@app/app/Routes';+import RuntimeConfig from '@app/features/app/state/RuntimeConfig';+import * as AuthenticationCommands from '@app/features/auth/commands/AuthenticationCommands';+import {AccountList} from '@app/features/auth/components/accounts/AccountList';+import {USE_ANOTHER_ACCOUNT_DESCRIPTOR} from '@app/features/auth/components/accounts/account_switcher_modal/AccountPickerShared';+import {AccountSwitcherAuthFlow} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthFlow';+import {+ type AccountSwitcherAuthPurpose,+ AccountSwitcherAuthPurposeType,+} from '@app/features/auth/components/accounts/account_switcher_modal/AccountSwitcherAuthTypes';import styles from '@app/features/auth/components/pages/OAuthAuthorizePage.module.css';import {getAccountKey} from '@app/features/auth/state/AccountStorageKey';-import {useAccountSwitcherLogic} from '@app/features/auth/utils/AccountSwitcherModalUtils';+import {currentInstanceAccounts} from '@app/features/auth/state/AccountSwitcherAccounts';+import Accounts from '@app/features/auth/state/Accounts';+import {AuthRegisterDraftContext, useAuthRegisterDraft} from '@app/features/auth/state/AuthRegisterDraftContext';+import {+ logoutCurrentAccountFromSwitcher,+ logoutStoredAccountFromSwitcher,+ switchStoredAccountFromSwitcher,+} from '@app/features/auth/utils/AccountSwitcherModalUtils';import {CANCEL_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import {setPathQueryParams} from '@app/features/messaging/utils/MessagingUrlUtils';import type {Account} from '@app/features/platform/state/AuthSession';import {remFromPx} from '@app/features/theme/layout/RemFromPx';import {Button} from '@app/features/ui/button/Button';import {msg} from '@lingui/core/macro';import {useLingui} from '@lingui/react/macro';-import {PlusIcon} from '@phosphor-icons/react';+import {UserPlusIcon} from '@phosphor-icons/react';import {observer} from 'mobx-react-lite';import type React from 'react';-import {useCallback} from 'react';+import {useCallback, useEffect, useRef, useState} from 'react';const CHOOSE_AN_ACCOUNT_DESCRIPTOR = msg({message: 'Choose an account',@@ -25,101 +41,193 @@ const CLIENT_WILL_USE_THIS_ACCOUNT_DESCRIPTOR = msg({comment:'OAuth authorization account step description. {clientName} is the OAuth application name requesting access.',});-const ADD_AN_ACCOUNT_TO_CONTINUE_DESCRIPTOR = msg({- message: 'Add an account to continue.',- comment: 'OAuth authorization empty state shown when there are no saved accounts to choose from.',-});-const ADD_AN_ACCOUNT_DESCRIPTOR = msg({- message: 'Add an account',- comment: 'OAuth authorization account step button. Opens the flow to sign in with another account.',-});const CONTINUE_DESCRIPTOR = msg({message: 'Continue',comment: 'OAuth authorization primary button. Advances to the next step after choosing an account.',});+function isUsable(account: Account | null): account is Account {+ return account != null && account.isValid !== false;+}++function initialSignInPurpose(+ sessionExpired: boolean,+ accounts: ReadonlyArray<Account>,+): AccountSwitcherAuthPurpose | null {+ const currentAccount = Accounts.currentAccount;+ if (sessionExpired && currentAccount != null) {+ return {type: AccountSwitcherAuthPurposeType.RELOGIN, account: currentAccount};+ }+ if (accounts.length === 0) {+ return {type: AccountSwitcherAuthPurposeType.ADD, instance: RuntimeConfig.getSnapshotOrNull()};+ }+ return null;+}++function currentPageLoginPath(): string {+ return setPathQueryParams(Routes.LOGIN, {redirect_to: `${window.location.pathname}${window.location.search}`});+}+interface OAuthAccountStepProps {clientLabel: string;+ sessionExpired: boolean;onCancel: () => void;onContinue: () => void;+ onAccountChanged: () => void;}-export const OAuthAccountStep: React.FC<OAuthAccountStepProps> = observer(({clientLabel, onCancel, onContinue}) => {- const {i18n} = useLingui();- const openAccountSwitcher = useCallback((reloginAccount: Account | null) => {- openAccountSwitcherModal(- {- closeCurrentAccountOnSelect: true,- initialReloginAccount: reloginAccount,- redirectAfterLogin: null,+export const OAuthAccountStep: React.FC<OAuthAccountStepProps> = observer(+ ({clientLabel, sessionExpired, onCancel, onContinue, onAccountChanged}) => {+ const {i18n} = useLingui();+ const authRegisterDraftContextValue = useAuthRegisterDraft();+ const accounts = currentInstanceAccounts();+ const currentAccountKey = Accounts.currentAccountKey;+ const isBusy = Accounts.isSwitching || Accounts.isLoading;+ const [signInPurpose, setSignInPurpose] = useState<AccountSwitcherAuthPurpose | null>(() =>+ initialSignInPurpose(sessionExpired, accounts),+ );+ const [chosenAccountKey, setChosenAccountKey] = useState<string | null>(() =>+ !sessionExpired && isUsable(Accounts.currentAccount) ? currentAccountKey : null,+ );+ const [error, setError] = useState<string | null>(null);+ const [focusSignInOnShow, setFocusSignInOnShow] = useState(false);+ const [returnFocusPurpose, setReturnFocusPurpose] = useState<AccountSwitcherAuthPurpose | null>(null);+ const activeRowRef = useRef<HTMLButtonElement | null>(null);+ const addAccountButtonRef = useRef<HTMLButtonElement | null>(null);+ const chosenAccount = accounts.find((account) => getAccountKey(account) === chosenAccountKey) ?? null;+ const startRelogin = useCallback((account: Account) => {+ setSignInPurpose({type: AccountSwitcherAuthPurposeType.RELOGIN, account});+ setFocusSignInOnShow(true);+ }, []);+ const startAddAccount = useCallback(() => {+ setSignInPurpose({type: AccountSwitcherAuthPurposeType.ADD, instance: RuntimeConfig.getSnapshotOrNull()});+ setFocusSignInOnShow(true);+ }, []);+ const handleSelect = useCallback(+ (account: Account) => {+ if (account.isValid === false) {+ startRelogin(account);+ return;+ }+ setChosenAccountKey(getAccountKey(account));+ },+ [startRelogin],+ );+ const handleContinue = useCallback(() => {+ if (!isUsable(chosenAccount)) {+ return;+ }+ const accountKey = getAccountKey(chosenAccount);+ if (accountKey === currentAccountKey && !sessionExpired) {+ onContinue();+ return;+ }+ setError(null);+ void switchStoredAccountFromSwitcher({+ accountKey,+ onSessionExpired: startRelogin,+ onSuccess: onAccountChanged,+ onError: setError,redirectAfterSwitch: null,switchAccount: null,- 'data-flx': 'auth.o-auth-authorize-page.account-step.account-switcher-modal',- },- null,+ });+ }, [chosenAccount, currentAccountKey, onAccountChanged, onContinue, sessionExpired, startRelogin]);+ const canSignOut = useCallback(+ (account: Account) => sessionExpired || getAccountKey(account) !== Accounts.currentAccountKey,+ [sessionExpired],);- }, []);- const {accounts, currentAccountKey, currentAccount, isBusy, handleSelectAccount} = useAccountSwitcherLogic({- onSelectCurrent: null,- onSessionExpired: openAccountSwitcher,- redirectAfterSwitch: null,- switchAccount: null,- });- const canContinue = Boolean(currentAccount && currentAccount.isValid !== false);- const handleAddAccount = useCallback(() => {- openAccountSwitcher(null);- }, [openAccountSwitcher]);- return (- <div className={styles.page} data-flx="auth.o-auth-authorize-page.account-step.page">- <div className={styles.heroCard} data-flx="auth.o-auth-authorize-page.account-step.hero-card">- <div className={styles.heroCopy} data-flx="auth.o-auth-authorize-page.account-step.hero-copy">- <h1 className={styles.heroTitle} data-flx="auth.o-auth-authorize-page.account-step.hero-title">- {i18n._(CHOOSE_AN_ACCOUNT_DESCRIPTOR)}- </h1>- <p className={styles.heroDescription} data-flx="auth.o-auth-authorize-page.account-step.hero-description">- {i18n._(CLIENT_WILL_USE_THIS_ACCOUNT_DESCRIPTOR, {clientName: clientLabel})}- </p>+ const handleSignOut = useCallback(async (account: Account) => {+ setError(null);+ if (getAccountKey(account) === Accounts.currentAccountKey) {+ await logoutCurrentAccountFromSwitcher(currentPageLoginPath(), setError);+ return;+ }+ await logoutStoredAccountFromSwitcher(account, setError);+ }, []);+ const backToAccounts = useCallback(() => {+ AuthenticationCommands.clearMfaTicket();+ setReturnFocusPurpose(signInPurpose);+ setSignInPurpose(null);+ }, [signInPurpose]);+ useEffect(() => {+ if (signInPurpose != null || returnFocusPurpose == null) {+ return;+ }+ setReturnFocusPurpose(null);+ if (returnFocusPurpose.type === AccountSwitcherAuthPurposeType.RELOGIN) {+ activeRowRef.current?.focus();+ return;+ }+ addAccountButtonRef.current?.focus();+ }, [returnFocusPurpose, signInPurpose]);+ if (signInPurpose != null) {+ return (+ <div className={styles.page} data-flx="auth.o-auth-authorize-page.account-step.sign-in">+ <AuthRegisterDraftContext.Provider value={authRegisterDraftContextValue}>+ <AccountSwitcherAuthFlow+ purpose={signInPurpose}+ renderFrame={null}+ redirectAfterLogin={null}+ focusOnEntry={focusSignInOnShow}+ exitCancels={accounts.length === 0}+ onExit={accounts.length === 0 ? onCancel : backToAccounts}+ onLoginComplete={onAccountChanged}+ data-flx="auth.o-auth-authorize-page.account-step.account-switcher-auth-flow"+ />+ </AuthRegisterDraftContext.Provider></div>- </div>- <div className={styles.accountList} data-flx="auth.o-auth-authorize-page.account-step.account-list">- {accounts.length === 0 ? (- <div className={styles.emptyState} data-flx="auth.o-auth-authorize-page.account-step.empty-state">- {i18n._(ADD_AN_ACCOUNT_TO_CONTINUE_DESCRIPTOR)}+ );+ }+ return (+ <div className={styles.page} data-flx="auth.o-auth-authorize-page.account-step.page">+ <div className={styles.heroCard} data-flx="auth.o-auth-authorize-page.account-step.hero-card">+ <div className={styles.heroCopy} data-flx="auth.o-auth-authorize-page.account-step.hero-copy">+ <h1 className={styles.heroTitle} data-flx="auth.o-auth-authorize-page.account-step.hero-title">+ {i18n._(CHOOSE_AN_ACCOUNT_DESCRIPTOR)}+ </h1>+ <p className={styles.heroDescription} data-flx="auth.o-auth-authorize-page.account-step.hero-description">+ {i18n._(CLIENT_WILL_USE_THIS_ACCOUNT_DESCRIPTOR, {clientName: clientLabel})}+ </p></div>- ) : (- accounts.map((account) => {- const accountKey = getAccountKey(account);- const isCurrent = accountKey === currentAccountKey;- const canClick = !isCurrent || account.isValid === false;- return (- <AccountRow- key={accountKey}- account={account}- isCurrent={isCurrent}- isExpired={account.isValid === false}- onClick={canClick ? () => handleSelectAccount(account) : undefined}- data-flx="auth.o-auth-authorize-page.account-step.account-row"- />- );- })- )}- </div>- <Button- type="button"- variant="secondary"- leftIcon={- <PlusIcon size={remFromPx(18)} weight="bold" data-flx="auth.o-auth-authorize-page.account-step.plus-icon" />- }- onClick={handleAddAccount}- disabled={isBusy}- fitContainer- data-flx="auth.o-auth-authorize-page.account-step.button.add-account"- >- {i18n._(ADD_AN_ACCOUNT_DESCRIPTOR)}- </Button>- <div className={styles.sectionDivider} data-flx="auth.o-auth-authorize-page.account-step.section-divider" />- <div className={styles.actions} data-flx="auth.o-auth-authorize-page.account-step.actions">- <div className={styles.actionButton} data-flx="auth.o-auth-authorize-page.account-step.action-button.cancel">+ </div>+ <AccountList+ accounts={accounts}+ currentAccountKey={sessionExpired ? null : currentAccountKey}+ selectedAccountKey={chosenAccountKey}+ initialActiveAccountKey={+ returnFocusPurpose?.type === AccountSwitcherAuthPurposeType.RELOGIN+ ? getAccountKey(returnFocusPurpose.account)+ : null+ }+ activeRowRef={activeRowRef}+ emptyFocusRef={addAccountButtonRef}+ error={error}+ disabled={isBusy}+ onSelect={handleSelect}+ onSignOut={handleSignOut}+ canSignOut={canSignOut}+ data-flx="auth.o-auth-authorize-page.account-step.account-list"+ />+ <Button+ ref={addAccountButtonRef}+ type="button"+ variant="secondary"+ leftIcon={+ <UserPlusIcon+ size={remFromPx(18)}+ weight="bold"+ data-flx="auth.o-auth-authorize-page.account-step.user-plus-icon"+ />+ }+ onClick={startAddAccount}+ disabled={isBusy}+ fitContainer+ data-flx="auth.o-auth-authorize-page.account-step.button.add-account"+ >+ {i18n._(USE_ANOTHER_ACCOUNT_DESCRIPTOR)}+ </Button>+ <div className={styles.sectionDivider} data-flx="auth.o-auth-authorize-page.account-step.section-divider" />+ <div className={styles.actions} data-flx="auth.o-auth-authorize-page.account-step.actions"><Buttontype="button"variant="secondary"@@ -130,12 +238,11 @@ export const OAuthAccountStep: React.FC<OAuthAccountStepProps> = observer(({clie>{i18n._(CANCEL_DESCRIPTOR)}</Button>- </div>- <div className={styles.actionButton} data-flx="auth.o-auth-authorize-page.account-step.action-button.continue"><Buttontype="button"- onClick={onContinue}- disabled={!canContinue || isBusy}+ onClick={handleContinue}+ disabled={!isUsable(chosenAccount)}+ submitting={isBusy}className={styles.actionButton}data-flx="auth.o-auth-authorize-page.account-step.button.continue">@@ -143,6 +250,6 @@ export const OAuthAccountStep: React.FC<OAuthAccountStepProps> = observer(({clie</Button></div></div>- </div>- );-});+ );+ },+);diff --git a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizeFlowPanel.tsx b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizeFlowPanel.tsxindex 7a072b0b2..2580d64fc 100644--- a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizeFlowPanel.tsx+++ b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizeFlowPanel.tsx@@ -21,12 +21,13 @@ export const AUTHORIZE_APPLICATION_DESCRIPTOR = msg({interface OAuthAuthorizeFlowPanelProps {flow: AuthorizeFlow;+ onAccountChanged?: () => void;onDone?: () => void;showInlineActions?: boolean;}export const OAuthAuthorizeFlowPanel: React.FC<OAuthAuthorizeFlowPanelProps> = observer(- ({flow, onDone, showInlineActions = true}) => {+ ({flow, onAccountChanged, onDone, showInlineActions = true}) => {const {i18n} = useLingui();if (flow.submitError) {return (@@ -43,6 +44,18 @@ export const OAuthAuthorizeFlowPanel: React.FC<OAuthAuthorizeFlowPanelProps> = o<AuthLoadingState data-flx="auth.oauth-authorize-page.o-auth-authorize-flow-panel.o-auth-loading-state" />);case 'session_expired':+ if (flow.includesAccountStep && onAccountChanged != null) {+ return (+ <OAuthAccountStep+ clientLabel={flow.clientLabel}+ sessionExpired+ onCancel={flow.onCancel}+ onContinue={onAccountChanged}+ onAccountChanged={onAccountChanged}+ data-flx="auth.oauth-authorize-page.o-auth-authorize-flow-panel.o-auth-account-step--session-expired"+ />+ );+ }return (<OAuthErrorStateerror={flow.sessionExpiredMessage}@@ -83,8 +96,10 @@ export const OAuthAuthorizeFlowPanel: React.FC<OAuthAuthorizeFlowPanelProps> = oreturn (<OAuthAccountStepclientLabel={flow.clientLabel}+ sessionExpired={false}onCancel={flow.onCancel}onContinue={flow.goNext}+ onAccountChanged={onAccountChanged ?? flow.goNext}data-flx="auth.oauth-authorize-page.o-auth-authorize-flow-panel.render-review-step.o-auth-account-step"/>);@@ -157,6 +172,7 @@ export const OAuthAuthorizeFlowPanel: React.FC<OAuthAuthorizeFlowPanelProps> = oscopesAdjusted={flow.scopesAdjusted}selectedScopes={flow.selectedScopes}showInlineActions={showInlineActions}+ showAccount={flow.includesAccountStep}isScopeLocked={flow.isScopeLocked}submitting={flow.submitting}data-flx="auth.oauth-authorize-page.o-auth-authorize-flow-panel.render-review-step.o-auth-scopes-step"diff --git a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizingAccount.tsx b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizingAccount.tsxnew file mode 100644index 000000000..86f28f7e0--- /dev/null+++ b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizingAccount.tsx@@ -0,0 +1,58 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {useAccountAvatarURL} from '@app/features/auth/AccountAvatarUtils';+import {useAccountDisplayIdentityView} from '@app/features/auth/components/accounts/AccountIdentity';+import styles from '@app/features/auth/components/pages/OAuthAuthorizePage.module.css';+import Accounts from '@app/features/auth/state/Accounts';+import type {Account} from '@app/features/platform/state/AuthSession';+import {MockAvatar} from '@app/features/ui/components/MockAvatar';+import {Trans} from '@lingui/react/macro';+import {observer} from 'mobx-react-lite';+import type React from 'react';++const AuthorizingAccountRow = observer(function AuthorizingAccountRow({+ account,+}: {+ readonly account: Account;+}): React.ReactElement {+ const avatarUrl = useAccountAvatarURL(account);+ const identityView = useAccountDisplayIdentityView(account);+ const displayName = identityView.displayLabel;+ return (+ <p className={styles.authorizingAccount} data-flx="auth.o-auth-authorize-page.authorizing-account.row">+ <span+ className={styles.authorizingAccountAvatar}+ data-flx="auth.o-auth-authorize-page.authorizing-account.avatar"+ >+ <MockAvatar+ size={24}+ avatarUrl={avatarUrl}+ userTag={identityView.tagLabel}+ data-flx="auth.o-auth-authorize-page.authorizing-account.mock-avatar"+ />+ </span>+ <span+ className={styles.authorizingAccountText}+ dir="auto"+ data-flx="auth.o-auth-authorize-page.authorizing-account.text"+ >+ <Trans comment="Line on the app authorization page that names the account the app will get access to. The tag wraps the account display name.">+ Signed in as{' '}+ <strong data-flx="auth.oauth-authorize-page.o-auth-authorizing-account.authorizing-account-row.strong">+ {displayName}+ </strong>+ </Trans>+ </span>+ </p>+ );+});++export const OAuthAuthorizingAccount = observer(function OAuthAuthorizingAccount(): React.ReactElement | null {+ const account = Accounts.currentAccount;+ if (account == null) {+ return null;+ }+ return (+ <AuthorizingAccountRow account={account} data-flx="auth.o-auth-authorize-page.authorizing-account.account-row" />+ );+});diff --git a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthScopesStep.tsx b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthScopesStep.tsxindex 532795f30..0feafa782 100644--- a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthScopesStep.tsx+++ b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/OAuthScopesStep.tsx@@ -7,8 +7,8 @@ import type {AuthorizeParams,PublicAppData,} from '@app/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizePageShared';+import {OAuthAuthorizingAccount} from '@app/features/auth/components/pages/oauth_authorize_page/OAuthAuthorizingAccount';import {Switch} from '@app/features/ui/components/form/FormSwitch';-import type {OAuth2Scope} from '@fluxer/constants/src/OAuth2Constants';import {msg} from '@lingui/core/macro';import {Trans, useLingui} from '@lingui/react/macro';import type React from 'react';@@ -45,6 +45,7 @@ interface OAuthScopesStepProps {scopesAdjusted: boolean;selectedScopes: ReadonlySet<string>;showInlineActions?: boolean;+ showAccount: boolean;isScopeLocked: (scope: string) => boolean;submitting: 'approve' | 'deny' | null;}@@ -68,6 +69,7 @@ export const OAuthScopesStep: React.FC<OAuthScopesStepProps> = ({scopesAdjusted,selectedScopes,showInlineActions = true,+ showAccount,isScopeLocked,submitting,}) => {@@ -91,13 +93,12 @@ export const OAuthScopesStep: React.FC<OAuthScopesStepProps> = ({<p className={styles.sectionDescription} data-flx="auth.o-auth-authorize-page.request-summary">{botInviteWithoutRedirect? i18n._(BOT_INVITE_NO_EXTERNAL_REDIRECT_DESCRIPTOR)- : authParams.channelId- ? authParams.channelId- : authParams.guildId- ? authParams.guildId- : i18n._(BOT_SCOPE_REQUESTED_DESCRIPTOR)}+ : authParams.channelId || authParams.guildId || i18n._(BOT_SCOPE_REQUESTED_DESCRIPTOR)}</p>) : null}+ {showAccount ? (+ <OAuthAuthorizingAccount data-flx="auth.o-auth-authorize-page.scopes-step.authorizing-account" />+ ) : null}</div></div><div className={styles.sectionDivider} data-flx="auth.o-auth-authorize-page.section-divider--6" />@@ -143,7 +144,7 @@ export const OAuthScopesStep: React.FC<OAuthScopesStepProps> = ({className={styles.scopeDescription}data-flx="auth.o-auth-authorize-page.scope-description">- {getOAuth2ScopeDescription(i18n, scope as OAuth2Scope) ?? scope}+ {getOAuth2ScopeDescription(i18n, scope) ?? scope}</span>}data-flx="auth.o-auth-authorize-page.switch.toggle-scope"diff --git a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/hooks/useOAuthPublicApp.ts b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/hooks/useOAuthPublicApp.tsindex 1734d0ddf..73d5e8e30 100644--- a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/hooks/useOAuthPublicApp.ts+++ b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/hooks/useOAuthPublicApp.ts@@ -50,8 +50,9 @@ export function useOAuthPublicApp(clientId: string | null): PublicAppState {return;}if (currentUser && currentUser.id === currentUserId && currentAccountKey != null) {- const userData = authResponseUserToUserData(currentUser);- if (userData) {+ const freshUserData = authResponseUserToUserData(currentUser);+ if (freshUserData) {+ const userData = {...Accounts.getAccount(currentAccountKey)?.userData, ...freshUserData};Accounts.updateAccountUserData(currentAccountKey, userData);void accountStorage.updateAccountUserData(currentAccountKey, userData).catch((error) => {logger.warn(`Failed to persist account user data for ${currentAccountKey}`, error);diff --git a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/state/useAuthorizeFlow.ts b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/state/useAuthorizeFlow.tsindex 35c0ce614..1608610b7 100644--- a/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/state/useAuthorizeFlow.ts+++ b/fluxer_app/src/features/auth/components/pages/oauth_authorize_page/state/useAuthorizeFlow.ts@@ -95,6 +95,7 @@ const CHOOSE_EITHER_A_COMMUNITY_OR_GROUP_DM_DESCRIPTOR = msg({export interface AuthorizeFlow {phase: AuthorizePhase;+ includesAccountStep: boolean;sessionExpiredMessage: string;authParams: AuthorizeParams | null;publicApp: PublicAppData | null;@@ -132,9 +133,10 @@ export interface AuthorizeFlow {goBack: () => void;}-export interface UseAuthorizeFlowOptions {+interface UseAuthorizeFlowOptions {search?: string;includeAccountStep?: boolean;+ startAtConsent?: boolean;onCancel?: () => void;}@@ -148,7 +150,7 @@ function getCurrentInviteDestinationKey(): string | null {if (guildId === '@me') {return channelId ? createBotInviteDestinationKey('group_dm', channelId) : null;}- if (guildId !== '@favorites' && guildId !== '@discover' && guildId !== '@premium') {+ if (!guildId.startsWith('@')) {return createBotInviteDestinationKey('guild', guildId);}return null;@@ -169,7 +171,7 @@ function getLoginRedirectPath(): string {}export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): AuthorizeFlow {- const {search, includeAccountStep = true, onCancel: onCancelOverride} = options;+ const {search, includeAccountStep = true, startAtConsent = false, onCancel: onCancelOverride} = options;const {i18n} = useLingui();const paramsState = useAuthorizeParams(search);const {params, scopes, hasBotScope, isBotOnly, redirectHostname, botInviteWithoutRedirect} = paramsState;@@ -198,7 +200,7 @@ export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): Authori(ThreadGuilds.isActive(selectedGuildId) ||destinations.guilds.some((guild) => guild.id === selectedGuildId && guild.threadsActive)),);- const initialReviewStep: ReviewStep = includeAccountStep ? 'account' : 'scopes';+ const initialReviewStep: ReviewStep = includeAccountStep && !startAtConsent ? 'account' : 'scopes';const preFetchValidationError = useMemo(() => {if (!params) return i18n._(MISSING_CLIENT_ID_DESCRIPTOR);if (params.guildId && params.channelId) {@@ -272,9 +274,12 @@ export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): Authori]);useEffect(() => {if (phase.kind !== 'session_expired') return;+ const expiredAccount = Accounts.currentAccount;+ if (expiredAccount != null) {+ Accounts.markAccountInvalid(expiredAccount.storageKey, expiredAccount.token);+ }+ if (includeAccountStep) return;void import('@app/features/platform/state/AuthSession').then(async ({default: SessionManager}) => {- const expiredUserId = SessionManager.userId;- if (expiredUserId) SessionManager.markAccountInvalid(expiredUserId);try {await SessionManager.handleConnectionClosed(4004);window.location.replace(getLoginRedirectPath());@@ -282,7 +287,7 @@ export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): Authorilogger.error('Failed to complete the expired session transition', error);}});- }, [phase.kind]);+ }, [includeAccountStep, phase.kind]);const currentAccountKey = Accounts.currentAccountKey;useEffect(() => {setSelectedDestinationKey(null);@@ -293,11 +298,12 @@ export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): Authorireturn;}if (destinations.options.some((option) => option.value === selectedDestinationKey)) return;- const requestedDestinationKey = params?.channelId- ? createBotInviteDestinationKey('group_dm', params.channelId)- : params?.guildId- ? createBotInviteDestinationKey('guild', params.guildId)- : null;+ let requestedDestinationKey: string | null = null;+ if (params?.channelId) {+ requestedDestinationKey = createBotInviteDestinationKey('group_dm', params.channelId);+ } else if (params?.guildId) {+ requestedDestinationKey = createBotInviteDestinationKey('guild', params.guildId);+ }if (requestedDestinationKey) {if (destinations.status !== 'ready' && destinations.status !== 'error') return;setSelectedDestinationKey(@@ -435,13 +441,13 @@ export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): Authorireturn;}try {- if (params.redirectUri) {+ if (params.redirectUri && publicAppState.data) {if (!isSafeRedirectUri(params.redirectUri)) {setSubmitting(null);setSubmitError(i18n._(INVALID_REDIRECT_URI_DESCRIPTOR));return;}- if (publicAppState.data && !publicAppState.data.redirect_uris?.includes(params.redirectUri)) {+ if (!publicAppState.data.redirect_uris?.includes(params.redirectUri)) {setSubmitting(null);setSubmitError(i18n._(THE_PROVIDED_REDIRECT_URI_NOT_REGISTERED_DESCRIPTOR));return;@@ -466,6 +472,7 @@ export function useAuthorizeFlow(options: UseAuthorizeFlowOptions = {}): Authori);return {phase,+ includesAccountStep: includeAccountStep,sessionExpiredMessage,authParams: params,publicApp: publicAppState.data,