feat: track Memind product analytics
This commit is contained in:
@@ -21,6 +21,7 @@ export function createPortalApiAuthMiddleware({
|
||||
getLegacySessionToken = () => null,
|
||||
isPageDataPublicPath = () => false,
|
||||
isLegacyPageDataApiPath = () => false,
|
||||
isProductAnalyticsPublicPath = () => false,
|
||||
accessPolicyMode = PORTAL_ACCESS_POLICY_MODE.OFF,
|
||||
accessEnforcementConfig = Object.freeze({
|
||||
masterEnabled: false,
|
||||
@@ -99,13 +100,24 @@ export function createPortalApiAuthMiddleware({
|
||||
|
||||
const plazaPublic = isPortalPlazaOptionalUserPath(req.path, req.method);
|
||||
const pageDataPublic = isPageDataPublicPath(req.path, req.method);
|
||||
const productAnalyticsPublic = isProductAnalyticsPublicPath(
|
||||
req.path,
|
||||
req.method,
|
||||
);
|
||||
// The retired namespace must reach its explicit 410 route instead of
|
||||
// being converted into a misleading global 401/403 response.
|
||||
const legacyPageDataApi = isLegacyPageDataApiPath(req.path);
|
||||
|
||||
if (userAuth && tkmindProxy) {
|
||||
if (req.userSessionError) {
|
||||
if (plazaPublic || pageDataPublic || legacyPageDataApi) return next();
|
||||
if (
|
||||
plazaPublic ||
|
||||
pageDataPublic ||
|
||||
legacyPageDataApi ||
|
||||
productAnalyticsPublic
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
return res.status(503).json({ message: '用户认证服务不可用,请稍后重试' });
|
||||
}
|
||||
try {
|
||||
@@ -113,7 +125,14 @@ export function createPortalApiAuthMiddleware({
|
||||
const me = await userAuth.getMe(req.userToken);
|
||||
if (me) req.currentUser = me;
|
||||
}
|
||||
if (plazaPublic || pageDataPublic || legacyPageDataApi) return next();
|
||||
if (
|
||||
plazaPublic ||
|
||||
pageDataPublic ||
|
||||
legacyPageDataApi ||
|
||||
productAnalyticsPublic
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
if (!req.userSession) {
|
||||
return res.status(401).json({ message: '未授权,请重新登录' });
|
||||
}
|
||||
@@ -130,6 +149,7 @@ export function createPortalApiAuthMiddleware({
|
||||
}
|
||||
}
|
||||
|
||||
if (productAnalyticsPublic) return next();
|
||||
if (legacyAuth?.verify(getLegacySessionToken(req))) return next();
|
||||
return res.status(401).json({ message: '未授权,请重新登录' });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user