Skip to content

Commit 5072aa1

Browse files
committed
don't show territory selector; don't redirect to main domain
1 parent c930106 commit 5072aa1

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

components/nav/desktop/second-bar.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import { NavSelect, PostItem, Sorts, hasNavSelect } from '../common'
33
import styles from '../../header.module.css'
44

55
export default function SecondBar (props) {
6-
const { prefix, topNavKey, sub } = props
6+
const { prefix, topNavKey, isCustomDomain, sub } = props
77
if (!hasNavSelect(props)) return null
88
return (
99
<Navbar className='pt-0 pb-2'>
1010
<Nav
1111
className={styles.navbarNav}
1212
activeKey={topNavKey}
1313
>
14-
<NavSelect sub={sub} size='medium' className='me-1' />
15-
<div className='ms-2 d-flex'><Sorts {...props} className='ms-1' /></div>
14+
{!isCustomDomain && <NavSelect sub={sub} size='medium' className='me-1' />}
15+
<div className={`${!isCustomDomain ? 'ms-2' : ''} d-flex`}>
16+
<Sorts {...props} className={`${!isCustomDomain ? 'ms-1' : ''}`} />
17+
</div>
1618
<PostItem className='ms-auto me-0 d-none d-md-flex' prefix={prefix} />
1719
</Nav>
1820
</Navbar>

components/nav/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default function Navigation ({ sub }) {
1919
dropNavKey: isCustomDomain
2020
? path.split('/').slice(1).join('/')
2121
: path.split('/').slice(sub ? 2 : 1).join('/'),
22+
isCustomDomain,
2223
sub
2324
}
2425

components/nav/mobile/top-bar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import styles from '../../header.module.css'
33
import { Back, NavPrice, NavSelect, NavWalletSummary, SignUpButton, hasNavSelect } from '../common'
44
import { useMe } from '@/components/me'
55

6-
export default function TopBar ({ prefix, sub, path, pathname, topNavKey, dropNavKey }) {
6+
export default function TopBar ({ prefix, sub, path, pathname, topNavKey, dropNavKey, isCustomDomain }) {
77
const { me } = useMe()
8+
if (hasNavSelect({ path, pathname }) && isCustomDomain) return null
89
return (
910
<Navbar>
1011
<Nav

middleware.js

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,38 @@ export async function customDomainMiddleware (request, referrerResp) {
7070
return NextResponse.redirect(new URL(cleanPath + url.search, url.origin))
7171
}
7272

73-
// if territory path, retain custom domain
74-
if (pathname === '/' || TERRITORY_PATHS.some(p => pathname.startsWith(p))) {
75-
// if coming from main domain, handle auth automatically
76-
if (referer && referer === mainDomain) {
77-
const authResp = customDomainAuthMiddleware(request, url)
78-
if (authResp && authResp.status !== 200) {
79-
// copy referrer cookies to auth redirect
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-
)
91-
}
92-
return authResp
73+
// if coming from main domain, handle auth automatically
74+
if (referer && referer === mainDomain) {
75+
const authResp = customDomainAuthMiddleware(request, url)
76+
if (authResp && authResp.status !== 200) {
77+
// copy referrer cookies to auth redirect
78+
console.log('referrerResp', referrerResp)
79+
for (const cookie of referrerResp.cookies.getAll()) {
80+
authResp.cookies.set(
81+
cookie.name,
82+
cookie.value,
83+
{
84+
maxAge: cookie.maxAge,
85+
expires: cookie.expires,
86+
path: cookie.path
87+
}
88+
)
9389
}
90+
return authResp
9491
}
92+
}
9593

96-
// TODO: preserve referrer cookies in a DRY way
97-
98-
const internalUrl = new URL(url)
94+
const internalUrl = new URL(url)
9995

100-
// rewrite to the territory path if we're at the root
96+
// rewrite to the territory path if we're at the root
97+
if (pathname === '/' || TERRITORY_PATHS.some(p => pathname.startsWith(p))) {
10198
internalUrl.pathname = `/~${domainInfo.subName}${pathname === '/' ? '' : pathname}`
102-
console.log('Rewrite to:', internalUrl.pathname)
103-
104-
// rewrite to the territory path
105-
return NextResponse.rewrite(internalUrl)
10699
}
100+
console.log('Rewrite to:', internalUrl.pathname)
107101

108-
// redirect to main domain for non-territory paths
109-
// create redirect response but preserve referrer cookies
110-
const redirectResp = NextResponse.redirect(new URL(pathname, mainDomain))
111-
102+
// rewrite to the territory path
103+
const redirectResp = NextResponse.rewrite(internalUrl)
104+
// TODO: preserve referrer cookies in a DRY way
112105
for (const cookie of referrerResp.cookies.getAll()) {
113106
redirectResp.cookies.set(
114107
cookie.name,

pages/~/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ export default function Sub ({ ssrData }) {
2121
if (!data && !ssrData) return <PageLoading />
2222
const { sub } = data || ssrData
2323

24+
const path = router.asPath.split('?')[0]
25+
// TODO: this works but it can be better
26+
const isCustomDomain = sub && !path.includes(`/~${sub?.name}`)
27+
2428
return (
2529
<Layout sub={sub?.name}>
26-
{sub
30+
{sub && !isCustomDomain
2731
? <TerritoryHeader sub={sub} />
2832
: (
2933
<>

0 commit comments

Comments
 (0)