Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): add handoff and checkout routes, redirect register

Hampusdaa7d7992bd3
diff --git a/fluxer_app/src/app/router/components/RootComponent.tsx b/fluxer_app/src/app/router/components/RootComponent.tsx
index 25d21d223..05e2f30ef 100644
--- a/fluxer_app/src/app/router/components/RootComponent.tsx
+++ b/fluxer_app/src/app/router/components/RootComponent.tsx
@@ -15,7 +15,9 @@ import {
import {isClientBooting} from '@app/features/app/state/ClientReadiness';
import Initialization from '@app/features/app/state/Initialization';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
+import {AccountHandoffArrival} from '@app/features/auth/components/AccountHandoffArrival';
import {isHandoffRequest} from '@app/features/auth/flow/auth_login_core/useDesktopHandoffFlow';
+import {endAccountHandoffArrival, isAccountHandoffArrival} from '@app/features/auth/state/AccountHandoffCapture';
import Accounts from '@app/features/auth/state/Accounts';
import Authentication from '@app/features/auth/state/Authentication';
import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';
@@ -59,10 +61,12 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
const hasStartedRestoreRef = useRef(false);
const pathname = location.pathname;
const isHandoff = isHandoffRequest(location.searchParams);
+ const isHandoffArrival = isAccountHandoffArrival(pathname);
const isAutoRedirectExemptRoute = isAutoRedirectExemptPath(pathname);
const shouldSkipAutoRedirect = isAutoRedirectExemptRoute || (pathname === Routes.LOGIN && isHandoff);
const isStandaloneRoute = useMemo(() => {
return (
+ isHandoffArrival ||
pathname.startsWith(Routes.LOGIN) ||
pathname.startsWith(Routes.REGISTER) ||
pathname.startsWith(Routes.FORGOT_PASSWORD) ||
@@ -75,14 +79,13 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
pathname.startsWith(Routes.SSO_CALLBACK) ||
pathname.startsWith(Routes.REPORT) ||
pathname.startsWith(Routes.PREMIUM_CALLBACK) ||
- pathname.startsWith(Routes.AGE_VERIFICATION_CALLBACK) ||
pathname.startsWith(Routes.CONNECTION_CALLBACK) ||
pathname === '/__notfound' ||
pathname.startsWith('/invite/') ||
pathname.startsWith('/gift/') ||
pathname.startsWith('/theme/')
);
- }, [pathname]);
+ }, [isHandoffArrival, pathname]);
const shouldShowSelfHostedSetup = requiresSelfHostedSetup && !isStandaloneRoute;
const shouldBypassGateway = requiresSelfHostedSetup || isStandaloneRoute;
const authToken = SessionManager.token;
@@ -206,8 +209,12 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
}
pendingRedirectRef.current = null;
}, [Authentication.isAuthenticated, location.pathname]);
+ useEffect(() => {
+ if (pathname !== Routes.ME) endAccountHandoffArrival();
+ }, [pathname]);
useEffect(() => {
if (
+ isHandoffArrival ||
!isAuthenticated ||
hasRestoredLocation ||
hasStartedRestoreRef.current ||
@@ -232,6 +239,7 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
}
}
}, [
+ isHandoffArrival,
isAuthenticated,
hasRestoredLocation,
mobileLayoutState.enabled,
@@ -239,7 +247,7 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
canNavigateToProtectedRoutes,
location.pathname,
]);
- useLastLocationPersistence(location.pathname);
+ useLastLocationPersistence(isHandoffArrival ? null : location.pathname);
useEffect(() => {
if (!isAuthenticated || !hasRestoredLocation) return;
const previousMobileLayoutState = previousMobileLayoutStateRef.current;
@@ -357,10 +365,12 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
navigateWithHistoryStack,
normalizeInternalUrl,
]);
- const showBottomNav = shouldShowMobileBottomNav({
- mobileLayoutEnabled: mobileLayoutState.enabled,
- pathname,
- });
+ const showBottomNav =
+ !isHandoffArrival &&
+ shouldShowMobileBottomNav({
+ mobileLayoutEnabled: mobileLayoutState.enabled,
+ pathname,
+ });
if (shouldShowSelfHostedSetup) {
return <SelfHostedSetupWizardGate data-flx="app.router.root-component.self-hosted-setup-wizard-gate" />;
}
@@ -369,7 +379,11 @@ export const RootComponent: React.FC<{children?: React.ReactNode}> = observer(({
{!shouldShowLoadingSkeleton && (
<>
<KeyboardModeListener data-flx="app.router.root-component.keyboard-mode-listener" />
- {children}
+ {isHandoffArrival ? (
+ <AccountHandoffArrival data-flx="app.router.root-component.account-handoff-arrival" />
+ ) : (
+ children
+ )}
{showBottomNav && currentUser && (
<MobileBottomNav currentUser={currentUser} data-flx="app.router.root-component.mobile-bottom-nav" />
)}
diff --git a/fluxer_app/src/app/router/policy/AuthRouteRedirectPolicy.ts b/fluxer_app/src/app/router/policy/AuthRouteRedirectPolicy.ts
index bf75903c7..ab2bb4d72 100644
--- a/fluxer_app/src/app/router/policy/AuthRouteRedirectPolicy.ts
+++ b/fluxer_app/src/app/router/policy/AuthRouteRedirectPolicy.ts
@@ -5,6 +5,7 @@ import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {usesUsernameSignIn} from '@app/features/app/utils/AccountIdentityFeatures';
import {resolveForgotPasswordRedirect} from '@app/features/auth/flow/AccountRecoveryRedirects';
import {isHandoffRequest} from '@app/features/auth/flow/auth_login_core/useDesktopHandoffFlow';
+import {isAccountHandoffArrival} from '@app/features/auth/state/AccountHandoffCapture';
import Authentication from '@app/features/auth/state/Authentication';
import {safeRedirectTarget, safeRedirectTargetOrFallback} from '@app/features/auth/utils/SafeRedirect';
import {setPathQueryParams} from '@app/features/messaging/utils/MessagingUrlUtils';
@@ -13,6 +14,7 @@ import {Redirect, type RouteContext, type To} from '@app/features/platform/compo
import SessionManager from '@app/features/platform/state/AuthSession';
import {resolveDocumentURLFromRoot} from '@app/features/platform/URLOriginUtils';
import {Logger} from '@app/features/platform/utils/AppLogger';
+import {when} from 'mobx';
const logger = new Logger('AuthRouteRedirectPolicy');
@@ -86,6 +88,7 @@ export function whenAuthenticated(handler: AuthRouteEnterHandler): AuthRouteEnte
export const requireAuthentication: AuthRouteEnterHandler = afterSessionInitialization((context) =>
Authentication.isAuthenticated ||
+ isAccountHandoffArrival(context.url.pathname) ||
RuntimeConfig.getSnapshotOrNull() === null ||
RuntimeConfig.requiresSelfHostedSetup()
? undefined
@@ -144,3 +147,34 @@ export function resolveForgotPasswordEntry(context: RouteContext): Redirect | un
}
return whenAuthenticated(resolveHomeEntry)(context);
}
+
+function activeSnapshotUsesIdentifierFirst(): boolean {
+ const snapshot = RuntimeConfig.getSnapshotOrNull();
+ return snapshot?.features.identifier_first === true;
+}
+
+export function redirectRegisterToSignIn(
+ resolveSignInPath: (context: RouteContext) => string | null,
+ handler: AuthRouteEnterHandler | null = null,
+): AuthRouteEnterHandler {
+ const resolve = (context: RouteContext): Redirect | undefined => {
+ if (!activeSnapshotUsesIdentifierFirst()) {
+ return undefined;
+ }
+ const signInPath = resolveSignInPath(context);
+ return signInPath === null ? undefined : new Redirect(`${signInPath}${context.url.search}`);
+ };
+ return (context: RouteContext): Redirect | undefined => {
+ const handled = handler?.(context);
+ if (handled !== undefined) {
+ return handled;
+ }
+ if (RuntimeConfig.getSnapshotOrNull() === null) {
+ void when(() => RuntimeConfig.getSnapshotOrNull() !== null).then(() =>
+ applyDeferredSessionRedirect(context, resolve),
+ );
+ return undefined;
+ }
+ return resolve(context);
+ };
+}
diff --git a/fluxer_app/src/app/router/routes/AuthRoutes.tsx b/fluxer_app/src/app/router/routes/AuthRoutes.tsx
index d7700832d..22e56b25b 100644
--- a/fluxer_app/src/app/router/routes/AuthRoutes.tsx
+++ b/fluxer_app/src/app/router/routes/AuthRoutes.tsx
@@ -10,6 +10,7 @@ import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {type AuthRoutePage, createAuthRoutePage} from '@app/features/auth/flow/AuthLoadableRoutePage';
import {createRoute, type RouteBuilder} from '@app/features/platform/components/router/RouterBuilder';
import {NotFound, Redirect, type RouteContext} from '@app/features/platform/components/router/RouterTypes';
+import {planForCheckoutProduct, rememberPurchaseIntent} from '@app/features/premium/state/PurchaseIntent';
import {shouldShowPremiumFeatures} from '@app/features/premium/utils/PremiumUtils';
const AuthorizeIPPage = createAuthRoutePage(
@@ -153,10 +154,24 @@ function createShortLinkAuthRoutes({
];
}
-const inviteRouteEnterHandlers = ShortLinkRouteEnterPolicy.createHandlers({
+function shortLinkSignInPath(paramName: string, toSignIn: (value: string) => string) {
+ return (context: RouteContext): string | null => {
+ const value = context.params[paramName];
+ return value == null || value === '' ? null : toSignIn(value);
+ };
+}
+
+const inviteShortLinkHandlers = ShortLinkRouteEnterPolicy.createHandlers({
paramName: 'code',
openAcceptModal: ShortLinkAcceptModalOpener.openInvite,
});
+const inviteRouteEnterHandlers = {
+ onRegisterEnter: AuthRouteRedirectPolicy.redirectRegisterToSignIn(
+ shortLinkSignInPath('code', Routes.inviteLogin),
+ inviteShortLinkHandlers.onRegisterEnter,
+ ),
+ onLoginEnter: inviteShortLinkHandlers.onLoginEnter,
+};
const giftShortLinkHandlers = ShortLinkRouteEnterPolicy.createHandlers({
paramName: 'code',
openAcceptModal: ShortLinkAcceptModalOpener.openGift,
@@ -172,7 +187,12 @@ function whenGiftingAvailable(handler: AuthRouteRedirectPolicy.AuthRouteEnterHan
}
const giftRouteEnterHandlers = {
- onRegisterEnter: whenGiftingAvailable(giftShortLinkHandlers.onRegisterEnter),
+ onRegisterEnter: whenGiftingAvailable(
+ AuthRouteRedirectPolicy.redirectRegisterToSignIn(
+ shortLinkSignInPath('code', Routes.giftLogin),
+ giftShortLinkHandlers.onRegisterEnter,
+ ),
+ ),
onLoginEnter: whenGiftingAvailable(giftShortLinkHandlers.onLoginEnter),
};
const themeRouteEnterHandlers = ShortLinkRouteEnterPolicy.createHandlers({
@@ -201,6 +221,7 @@ const registerRoute = createAuthPageRoute({
path: '/register',
page: RegisterPage,
dataFlx: 'app.router.auth-routes.register-page',
+ onEnter: AuthRouteRedirectPolicy.redirectRegisterToSignIn(() => Routes.LOGIN),
});
const oauthAuthorizeRoute = createAuthPageRoute({
id: 'oauthAuthorize',
@@ -267,6 +288,19 @@ const authorizeIPRoute = createAuthPageRoute({
dataFlx: 'app.router.auth-routes.authorize-ip-page',
});
const pendingRoute = createAuthRedirectRoute('pending', Routes.PENDING);
+const checkoutRoute = createRoute({
+ getParentRoute: () => authLayoutRoute,
+ id: 'checkout',
+ path: Routes.CHECKOUT,
+ onEnter: (context) => {
+ const plan = planForCheckoutProduct(context.params['product'] ?? '');
+ if (plan === null || (RuntimeConfig.getSnapshotOrNull() !== null && !shouldShowPremiumFeatures())) {
+ return new Redirect(Routes.ME);
+ }
+ rememberPurchaseIntent(plan);
+ return new Redirect(Routes.PLUTONIUM);
+ },
+});
const reportRoute = createAuthPageRoute({
id: 'report',
path: Routes.REPORT,
@@ -278,7 +312,10 @@ const themeRegisterRoute = createAuthPageRoute({
path: Routes.THEME_REGISTER,
page: ThemeRegisterPage,
dataFlx: 'app.router.auth-routes.theme-register-page',
- onEnter: themeRouteEnterHandlers.onRegisterEnter,
+ onEnter: AuthRouteRedirectPolicy.redirectRegisterToSignIn(
+ shortLinkSignInPath('themeId', Routes.themeLogin),
+ themeRouteEnterHandlers.onRegisterEnter,
+ ),
});
const themeLoginRoute = createAuthPageRoute({
id: 'themeLogin',
@@ -307,5 +344,6 @@ export const authRouteTree = authLayoutRoute.addChildren([
verifyEmailRoute,
authorizeIPRoute,
pendingRoute,
+ checkoutRoute,
reportRoute,
]);
diff --git a/fluxer_app/src/index.tsx b/fluxer_app/src/index.tsx
index b73386341..3cf44aea3 100644
--- a/fluxer_app/src/index.tsx
+++ b/fluxer_app/src/index.tsx
@@ -18,6 +18,7 @@ import '@app/features/theme/styles/preflight.css';
import {resolveDomainMigrationSide} from '@app/features/app/domain_migration/DomainMigrationCore';
import {runDomainMigrationPreMount} from '@app/features/app/domain_migration/DomainMigrationPreMount';
import {installRuntimeConfigEffects} from '@app/features/app/state/RuntimeConfigEffects';
+import {captureAccountHandoffFromLocation} from '@app/features/auth/state/AccountHandoffCapture';
import {installImageRetention} from '@app/features/messaging/utils/ImageRetention';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {loadLazyModule} from '@app/features/platform/utils/LazyModuleLoader';
@@ -27,6 +28,7 @@ import {configure} from 'mobx';
const logger = new Logger('index');
+captureAccountHandoffFromLocation();
installBrowserStorageAccessProtection();
installUnhandledRejectionReporter();