@lobehub/chat 1.80.1 → 1.80.2

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.
@@ -1,15 +1,17 @@
1
1
  import { enableClerk, enableNextAuth } from '@/const/auth';
2
- import { ClerkAuth } from '@/libs/clerk-auth';
3
- import NextAuthEdge from '@/libs/next-auth/edge';
4
2
 
5
3
  export const getUserAuth = async () => {
6
4
  if (enableClerk) {
5
+ const { ClerkAuth } = await import('@/libs/clerk-auth');
6
+
7
7
  const clerkAuth = new ClerkAuth();
8
8
 
9
9
  return await clerkAuth.getAuth();
10
10
  }
11
11
 
12
12
  if (enableNextAuth) {
13
+ const { default: NextAuthEdge } = await import('@/libs/next-auth/edge');
14
+
13
15
  const session = await NextAuthEdge.auth();
14
16
 
15
17
  const userId = session?.user.id;
@@ -19,3 +21,25 @@ export const getUserAuth = async () => {
19
21
 
20
22
  throw new Error('Auth method is not enabled');
21
23
  };
24
+
25
+ /**
26
+ * 从授权头中提取 Bearer Token
27
+ * @param authHeader - 授权头 (例如 "Bearer xxx")
28
+ * @returns Bearer Token 或 null(如果授权头无效或不存在)
29
+ */
30
+ export const extractBearerToken = (authHeader?: string | null): string | null => {
31
+ if (!authHeader) return null;
32
+
33
+ const trimmedHeader = authHeader.trim(); // Trim leading/trailing spaces
34
+
35
+ // Check if it starts with 'Bearer ' (case-insensitive check might be desired depending on spec)
36
+ if (!trimmedHeader.toLowerCase().startsWith('bearer ')) {
37
+ return null;
38
+ }
39
+
40
+ // Extract the token part after "Bearer " and trim potential spaces around the token itself
41
+ const token = trimmedHeader.slice(7).trim();
42
+
43
+ // Return the token only if it's not an empty string after trimming
44
+ return token || null;
45
+ };