feat: handle ecid and loginType params from mobile app
This commit is contained in:
@@ -21,6 +21,29 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
const { nextUrl } = request
|
||||
const lang = findLang(nextUrl.pathname)
|
||||
|
||||
const loginTypeHeader = request.headers.get("loginType")
|
||||
const loginTypeSearchParam = nextUrl.searchParams.get("loginType")
|
||||
|
||||
const adobeMc = nextUrl.searchParams.get("adobe_mc")
|
||||
|
||||
const headers = getDefaultRequestHeaders(request)
|
||||
|
||||
// LoginType is passed from the mobile app as a header and needs to be passed around with each subsequent
|
||||
// request within webviews due to tracking. We set the loginType as a header and pass it along to future
|
||||
// requests, and to read it from TRPC side (which is where the tracking object is created).
|
||||
// The value is appended to all webview links as a search param, just like adobe_mc.
|
||||
const loginType = loginTypeHeader || loginTypeSearchParam
|
||||
if (loginType) {
|
||||
headers.set("loginType", loginType)
|
||||
}
|
||||
|
||||
// adobe_mc (Experience Cloud ID) needs to be passed around as a search param, which will be read
|
||||
// from the URL by the tracking SDK. Adobe_mc is passed from the mobile app as a searchParam, and
|
||||
// then passed to nextjs as a header. In the RSC, the adobe_mc is appended as a searchParam on each webview link.
|
||||
if (adobeMc) {
|
||||
headers.set("adobe_mc", adobeMc)
|
||||
}
|
||||
|
||||
// If user is redirected to /lang/webview/refresh/, the webview token is invalid and we remove the cookie
|
||||
if (refreshWebviews.includes(nextUrl.pathname)) {
|
||||
return NextResponse.rewrite(
|
||||
@@ -44,7 +67,6 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
`Unable to resolve CMS entry for locale "${lang}": ${pathNameWithoutLang}`
|
||||
)
|
||||
}
|
||||
const headers = getDefaultRequestHeaders(request)
|
||||
headers.set("x-uid", uid)
|
||||
|
||||
const webviewToken = request.cookies.get("webviewToken")
|
||||
|
||||
Reference in New Issue
Block a user