File size: 4,032 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import config from '@automattic/calypso-config';
import { getLanguageRouteParam } from '@automattic/i18n-utils';
import { Provider as ReduxProvider } from 'react-redux';
import CalypsoI18nProvider from 'calypso/components/calypso-i18n-provider';
import { RouteProvider } from 'calypso/components/route';
import { setHrefLangLinks } from 'calypso/controller/localized-links';
import {
	setLocaleMiddleware,
	setSectionMiddleware,
	makeLayoutMiddleware,
} from 'calypso/controller/shared';
import LayoutLoggedOut from 'calypso/layout/logged-out';
import {
	login,
	magicLogin,
	qrCodeLogin,
	magicLoginUse,
	redirectJetpack,
	redirectDefaultLocale,
	desktopLogin,
	desktopLoginFinalize,
} from './controller';
import redirectLoggedIn from './redirect-logged-in';
import { setShouldServerSideRenderLogin, ssrSetupLocaleLogin, setMetaTags } from './ssr';

export const LOGIN_SECTION_DEFINITION = {
	name: 'login',
	paths: [ '/log-in' ],
	module: 'login',
	enableLoggedOut: true,
	isomorphic: true,
};

const ReduxWrappedLayout = ( {
	store,
	currentSection,
	currentRoute,
	currentQuery,
	primary,
	secondary,
	redirectUri,
	showGdprBanner,
	i18n,
} ) => {
	return (
		<CalypsoI18nProvider i18n={ i18n }>
			<RouteProvider
				currentSection={ currentSection }
				currentRoute={ currentRoute }
				currentQuery={ currentQuery }
			>
				<ReduxProvider store={ store }>
					<LayoutLoggedOut
						primary={ primary }
						secondary={ secondary }
						redirectUri={ redirectUri }
						showGdprBanner={ showGdprBanner }
					/>
				</ReduxProvider>
			</RouteProvider>
		</CalypsoI18nProvider>
	);
};

const makeLoggedOutLayout = makeLayoutMiddleware( ReduxWrappedLayout );

export default ( router ) => {
	const lang = getLanguageRouteParam();

	// The /log-in/desktop routes are only used by the WordPress.com Desktop app.
	router(
		[ `/log-in/desktop/${ lang }` ],
		redirectLoggedIn,
		setLocaleMiddleware(),
		setMetaTags,
		setSectionMiddleware( { ...LOGIN_SECTION_DEFINITION, isomorphic: false } ),
		desktopLogin,
		makeLoggedOutLayout
	);
	router(
		[ `/log-in/desktop/finalize` ],
		redirectLoggedIn,
		setLocaleMiddleware(),
		setMetaTags,
		setSectionMiddleware( { ...LOGIN_SECTION_DEFINITION, isomorphic: false } ),
		desktopLoginFinalize,
		makeLoggedOutLayout
	);

	if ( config.isEnabled( 'login/magic-login' ) ) {
		router(
			[ `/log-in/link/use/${ lang }`, `/log-in/jetpack/link/use/${ lang }` ],
			redirectLoggedIn,
			setLocaleMiddleware(),
			setMetaTags,
			setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
			magicLoginUse,
			makeLoggedOutLayout
		);

		router(
			[ `/log-in/link/${ lang }`, `/log-in/jetpack/link/${ lang }`, `/log-in/new/link/${ lang }` ],
			setLocaleMiddleware(),
			setMetaTags,
			setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
			magicLogin,
			makeLoggedOutLayout
		);
	}

	router(
		[ `/log-in/qr/${ lang }`, `/log-in/jetpack/qr/${ lang }` ],
		redirectLoggedIn,
		setLocaleMiddleware(),
		setMetaTags,
		setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
		qrCodeLogin,
		makeLoggedOutLayout
	);

	router(
		[
			`/log-in/:twoFactorAuthType(authenticator|backup|sms|push|webauthn)/${ lang }`,
			`/log-in/:flow(social-connect)/${ lang }`,
			`/log-in/:socialService(google|apple|github)/callback/${ lang }`,
			`/log-in/:isJetpack(jetpack)/${ lang }`,
			`/log-in/:isJetpack(jetpack)/:socialService(google|apple|github)/${ lang }`,
			`/log-in/:isJetpack(jetpack)/:twoFactorAuthType(authenticator|backup|sms|push|webauthn)/${ lang }`,
			`/log-in/:isJetpack(jetpack)/:action(lostpassword)/${ lang }`,
			`/log-in/:isGutenboarding(new)/${ lang }`,
			`/log-in/:isGutenboarding(new)/:twoFactorAuthType(authenticator|backup|sms|push|webauthn)/${ lang }`,
			`/log-in/:action(lostpassword)/${ lang }`,
			`/log-in/${ lang }`,
		],
		redirectJetpack,
		redirectDefaultLocale,
		setLocaleMiddleware(),
		setHrefLangLinks,
		setMetaTags,
		setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
		login,
		setShouldServerSideRenderLogin,
		ssrSetupLocaleLogin,
		makeLoggedOutLayout
	);
};