Skip to content

Commit c930106

Browse files
committed
fix Sorts active key; referrer cookies workaround; structure for territory domains editing
1 parent a39e5b0 commit c930106

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

components/nav/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import { PriceCarouselProvider } from './price-carousel'
77
export default function Navigation ({ sub }) {
88
const router = useRouter()
99
const path = router.asPath.split('?')[0]
10+
// TODO: this works but it can be better
11+
const isCustomDomain = sub && !path.includes(`/~${sub}`)
1012
const props = {
1113
prefix: sub ? `/~${sub}` : '',
1214
path,
1315
pathname: router.pathname,
14-
topNavKey: path.split('/')[sub ? 2 : 1] ?? '',
15-
dropNavKey: path.split('/').slice(sub ? 2 : 1).join('/'),
16+
topNavKey: isCustomDomain
17+
? path.split('/')[1] ?? ''
18+
: path.split('/')[sub ? 2 : 1] ?? '',
19+
dropNavKey: isCustomDomain
20+
? path.split('/').slice(1).join('/')
21+
: path.split('/').slice(sub ? 2 : 1).join('/'),
1622
sub
1723
}
1824

components/territory-domains.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function CustomDomainForm ({ sub }) {
5656
<div className='d-flex align-items-center gap-2'>
5757
<Input
5858
label={
59-
<div className='d-flex align-items-center'>
59+
<div className='d-flex align-items-center gap-2'>
6060
<span>domain</span>
6161
{error && <Info variant='danger'>error</Info>}
6262
{success && <Info variant='success'>Domain settings updated successfully!</Info>}

components/territory-form.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export default function TerritoryForm ({ sub }) {
257257
</ol>
258258
</Info>
259259
</div>
260-
}
260+
}
261261
name='moderated'
262262
groupClassName='ms-1'
263263
/>
@@ -273,10 +273,17 @@ export default function TerritoryForm ({ sub }) {
273273
</ol>
274274
</Info>
275275
</div>
276-
}
276+
}
277277
name='nsfw'
278278
groupClassName='ms-1'
279279
/>
280+
</>
281+
}
282+
/>
283+
<AccordianItem
284+
header={<div style={{ fontWeight: 'bold', fontSize: '92%' }}>personalization</div>}
285+
body={
286+
<>
280287
<TerritoryDomains sub={sub} />
281288
{sub?.customDomain?.verificationState === 'VERIFIED' &&
282289
<>
@@ -286,8 +293,7 @@ export default function TerritoryForm ({ sub }) {
286293
<div className='mb-3'>WIP</div>
287294
</>}
288295
</>
289-
290-
}
296+
}
291297
/>
292298
<div className='mt-3 d-flex justify-content-end'>
293299
<FeeButton

middleware.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,24 @@ export async function customDomainMiddleware (request, referrerResp) {
7777
const authResp = customDomainAuthMiddleware(request, url)
7878
if (authResp && authResp.status !== 200) {
7979
// copy referrer cookies to auth redirect
80-
for (const [key, value] of referrerResp.cookies.getAll()) {
81-
authResp.cookies.set(key, value.value, value)
80+
console.log('referrerResp', referrerResp)
81+
for (const cookie of referrerResp.cookies.getAll()) {
82+
authResp.cookies.set(
83+
cookie.name,
84+
cookie.value,
85+
{
86+
maxAge: cookie.maxAge,
87+
expires: cookie.expires,
88+
path: cookie.path
89+
}
90+
)
8291
}
8392
return authResp
8493
}
8594
}
8695

96+
// TODO: preserve referrer cookies in a DRY way
97+
8798
const internalUrl = new URL(url)
8899

89100
// rewrite to the territory path if we're at the root
@@ -98,9 +109,16 @@ export async function customDomainMiddleware (request, referrerResp) {
98109
// create redirect response but preserve referrer cookies
99110
const redirectResp = NextResponse.redirect(new URL(pathname, mainDomain))
100111

101-
// copy referrer cookies
102-
for (const [key, value] of referrerResp.cookies.getAll()) {
103-
redirectResp.cookies.set(key, value.value, value)
112+
for (const cookie of referrerResp.cookies.getAll()) {
113+
redirectResp.cookies.set(
114+
cookie.name,
115+
cookie.value,
116+
{
117+
maxAge: cookie.maxAge,
118+
expires: cookie.expires,
119+
path: cookie.path
120+
}
121+
)
104122
}
105123

106124
return redirectResp
@@ -279,6 +297,8 @@ export async function middleware (request) {
279297
return applySecurityHeaders(customDomainResp)
280298
}
281299

300+
console.log('applying security headers')
301+
282302
return applySecurityHeaders(referrerResp)
283303
}
284304

0 commit comments

Comments
 (0)