@windrun-huaiin/diaomao 14.3.3 → 14.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windrun-huaiin/diaomao",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"@radix-ui/react-slot": "^1.2.4",
|
|
28
28
|
"@tailwindcss/typography": "^0.5.19",
|
|
29
29
|
"@types/mdx": "^2.0.13",
|
|
30
|
-
"@windrun-huaiin/backend-core": "14.
|
|
30
|
+
"@windrun-huaiin/backend-core": "14.6.0",
|
|
31
31
|
"@windrun-huaiin/base-ui": "14.0.3",
|
|
32
32
|
"@windrun-huaiin/lib": "14.0.1",
|
|
33
|
-
"@windrun-huaiin/third-ui": "14.
|
|
33
|
+
"@windrun-huaiin/third-ui": "14.5.0",
|
|
34
34
|
"autoprefixer": "^10.4.27",
|
|
35
35
|
"class-variance-authority": "^0.7.1",
|
|
36
36
|
"clsx": "^2.1.1",
|
|
@@ -7,13 +7,11 @@ import { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
|
|
|
7
7
|
import { getTranslations } from 'next-intl/server';
|
|
8
8
|
import { CreditPopover } from '@/components/credit-popover';
|
|
9
9
|
import { ExtendedLinkItem, HomeTitle } from '@windrun-huaiin/third-ui/fuma/base';
|
|
10
|
-
import { getOptionalAuth } from '@windrun-huaiin/third-ui/clerk/patch/optional-auth';
|
|
11
10
|
import { getAsNeededLocalizedUrl } from '@windrun-huaiin/lib';
|
|
12
11
|
|
|
13
12
|
// home page normal menu
|
|
14
13
|
export async function homeNavLinks(locale: string): Promise<ExtendedLinkItem[]> {
|
|
15
14
|
const t1 = await getTranslations({ locale: locale, namespace: 'linkPreview' });
|
|
16
|
-
const { userId } = await getOptionalAuth();
|
|
17
15
|
return [
|
|
18
16
|
{
|
|
19
17
|
icon: <icons.BugOff />,
|
|
@@ -29,7 +27,7 @@ export async function homeNavLinks(locale: string): Promise<ExtendedLinkItem[]>
|
|
|
29
27
|
type: 'custom',
|
|
30
28
|
secondary: true,
|
|
31
29
|
mobilePinned: true,
|
|
32
|
-
children:
|
|
30
|
+
children: <CreditPopover locale={locale} />,
|
|
33
31
|
},
|
|
34
32
|
{
|
|
35
33
|
type: 'custom',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { creditService, subscriptionService
|
|
2
|
-
import {
|
|
1
|
+
import { creditService, subscriptionService } from '@windrun-huaiin/backend-core/database';
|
|
2
|
+
import { getOptionalServerAuthUser } from '@windrun-huaiin/backend-core/auth/server';
|
|
3
3
|
import { viewLocalTime } from '@windrun-huaiin/lib/utils';
|
|
4
4
|
import { CreditNavButton } from '@windrun-huaiin/third-ui/main';
|
|
5
5
|
import type { CreditOverviewData } from '@windrun-huaiin/third-ui/main/server';
|
|
@@ -14,17 +14,11 @@ interface CreditPopoverProps {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export async function CreditPopover({ locale }: CreditPopoverProps) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
if (!clerkUserId) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const user = await userService.findByClerkUserId(clerkUserId);
|
|
24
|
-
if (!user) {
|
|
25
|
-
console.warn('User not found!');
|
|
17
|
+
const authUser = await getOptionalServerAuthUser();
|
|
18
|
+
if (!authUser) {
|
|
26
19
|
return null;
|
|
27
20
|
}
|
|
21
|
+
const { user } = authUser;
|
|
28
22
|
|
|
29
23
|
const enableSubscriptionUpgrade = process.env.ENABLE_STRIPE_SUBSCRIPTION_UPGRADE !== 'false';
|
|
30
24
|
|
package/src/mdx/blog/index.mdx
CHANGED
package/src/mdx/blog/ioc.mdx
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
import { appConfig } from "@/lib/appConfig";
|
|
9
|
+
import { buildProtectedPageRoutePatterns, handleAuthMiddleware } from "@windrun-huaiin/backend-core/auth/middleware";
|
|
9
10
|
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
|
|
10
11
|
import createMiddleware from "next-intl/middleware";
|
|
11
12
|
import { NextRequest, NextResponse } from "next/server";
|
|
@@ -18,9 +19,12 @@ const intlMiddleware = createMiddleware({
|
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
// 需要身份认证的路由(页面路由)
|
|
21
|
-
const protectedPageRoutes = createRouteMatcher(
|
|
22
|
-
|
|
23
|
-
]
|
|
22
|
+
const protectedPageRoutes = createRouteMatcher(
|
|
23
|
+
buildProtectedPageRoutePatterns(
|
|
24
|
+
['/dashboard', '/settings', '/profile', '/billing'],
|
|
25
|
+
appConfig.i18n.locales
|
|
26
|
+
)
|
|
27
|
+
);
|
|
24
28
|
|
|
25
29
|
// 需要身份认证的API路由
|
|
26
30
|
const protectedApiRoutes = createRouteMatcher([
|
|
@@ -58,6 +62,16 @@ export default clerkMiddleware(
|
|
|
58
62
|
(loc) => pathname === `/${loc}` || pathname.startsWith(`/${loc}/`)
|
|
59
63
|
);
|
|
60
64
|
|
|
65
|
+
const authResponse = await handleAuthMiddleware(auth, req, {
|
|
66
|
+
protectedPageRoutes,
|
|
67
|
+
protectedApiRoutes,
|
|
68
|
+
publicApiRoutes,
|
|
69
|
+
intlMiddleware,
|
|
70
|
+
});
|
|
71
|
+
if (authResponse) {
|
|
72
|
+
return authResponse;
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
// 对于无语言前缀的页面请求,根据配置进行处理
|
|
62
76
|
// 避免落不到 [locale] 路由。
|
|
63
77
|
if (!hasLocalePrefix && !pathname.startsWith('/api/')) {
|
|
@@ -75,44 +89,6 @@ export default clerkMiddleware(
|
|
|
75
89
|
}
|
|
76
90
|
}
|
|
77
91
|
|
|
78
|
-
// 1. 处理需要认证的页面路由
|
|
79
|
-
if (protectedPageRoutes(req)) {
|
|
80
|
-
const { userId: clerkUserId } = await auth();
|
|
81
|
-
if (!clerkUserId) return (await auth()).redirectToSignIn();
|
|
82
|
-
|
|
83
|
-
// 对于页面路由,只设置 Clerk 用户信息
|
|
84
|
-
const response = intlMiddleware(req);
|
|
85
|
-
if (response) {
|
|
86
|
-
response.headers.set("x-clerk-user-id", clerkUserId);
|
|
87
|
-
console.log("Set clerk_user_id for protected page:", clerkUserId);
|
|
88
|
-
}
|
|
89
|
-
return response;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 2. 处理需要认证的API路由
|
|
93
|
-
if (protectedApiRoutes(req)) {
|
|
94
|
-
const { userId: clerkUserId } = await auth();
|
|
95
|
-
if (!clerkUserId) return (await auth()).redirectToSignIn();
|
|
96
|
-
|
|
97
|
-
// 只设置 Clerk 用户信息,让 API 自己处理数据库查询
|
|
98
|
-
const response = NextResponse.next();
|
|
99
|
-
response.headers.set("x-clerk-user-id", clerkUserId);
|
|
100
|
-
console.log("Set clerk_user_id for protected API:", clerkUserId);
|
|
101
|
-
return response;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 3. 免认证的API路由,直接通过
|
|
105
|
-
if (publicApiRoutes(req)) {
|
|
106
|
-
console.log("Public API route, no auth required:", req.nextUrl.pathname);
|
|
107
|
-
return NextResponse.next();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 4. 所有其他API路由都直接通过,不添加语言前缀
|
|
111
|
-
if (req.nextUrl.pathname.startsWith("/api/")) {
|
|
112
|
-
console.log("Other API route, no internationalization:", req.nextUrl.pathname);
|
|
113
|
-
return NextResponse.next();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
92
|
// 5. 其他路由使用默认的国际化中间件处理
|
|
117
93
|
|
|
118
94
|
// handle trailing slash redirect
|