@@ -14,7 +14,7 @@ const SN_REFERRER_NONCE = 'sn_referrer_nonce'
14
14
const SN_REFEREE_LANDING = 'sn_referee_landing'
15
15
16
16
const TERRITORY_PATHS = [ '/~' , '/recent' , '/random' , '/top' , '/post' , '/edit' ]
17
- const NO_REWRITE_PATHS = [ '/api' , '/_next' , '/_error' , '/404' , '/500' , '/offline' , '/static' , '/signup' , '/login' , '/ logout']
17
+ const NO_REWRITE_PATHS = [ '/api' , '/_next' , '/_error' , '/404' , '/500' , '/offline' , '/static' , '/logout' ]
18
18
19
19
// TODO: move this to a separate file
20
20
// fetch custom domain mappings from our API, caching it for 5 minutes
@@ -70,6 +70,14 @@ export async function customDomainMiddleware (request, referrerResp) {
70
70
console . log ( 'pathname' , pathname )
71
71
console . log ( 'query' , url . searchParams )
72
72
73
+ if ( pathname === '/login' || pathname === '/signup' ) {
74
+ const redirectUrl = new URL ( pathname , mainDomain )
75
+ redirectUrl . searchParams . set ( 'domain' , host )
76
+ redirectUrl . searchParams . set ( 'callbackUrl' , url . searchParams . get ( 'callbackUrl' ) )
77
+ const redirectResp = NextResponse . redirect ( redirectUrl )
78
+ return applyReferrerCookies ( redirectResp , referrerResp )
79
+ }
80
+
73
81
// if the url contains the territory path, remove it
74
82
if ( pathname . startsWith ( `/~${ domainInfo . subName } ` ) ) {
75
83
// remove the territory prefix from the path
@@ -80,12 +88,14 @@ export async function customDomainMiddleware (request, referrerResp) {
80
88
}
81
89
82
90
// if coming from main domain, handle auth automatically
83
- if ( referer && referer === mainDomain ) {
91
+ // TODO: uncomment and work on this
92
+
93
+ /* if (referer && referer === mainDomain) {
84
94
const authResp = customDomainAuthMiddleware(request, url)
85
95
if (authResp && authResp.status !== 200) {
86
96
return applyReferrerCookies(authResp, referrerResp)
87
97
}
88
- }
98
+ } */
89
99
90
100
const internalUrl = new URL ( url )
91
101
// rewrite to the territory path if we're at the root
0 commit comments