@zodic/shared 0.0.105 → 0.0.106
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 +1 -1
- package/utils/index.ts +12 -7
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { jwtVerify } from 'jose';
|
|
2
|
-
import { AuthCtx,
|
|
2
|
+
import { AuthCtx, JWKS } from '../types';
|
|
3
|
+
|
|
4
|
+
const base64UrlDecode = (input: string) => {
|
|
5
|
+
const base64 = input.replace(/-/g, '+').replace(/_/g, '/');
|
|
6
|
+
const decoded = atob(base64); // Cloudflare Workers supports `atob`
|
|
7
|
+
return JSON.parse(decoded);
|
|
8
|
+
};
|
|
3
9
|
|
|
4
10
|
export const verifyToken = async (
|
|
5
11
|
c: AuthCtx,
|
|
@@ -15,13 +21,12 @@ export const verifyToken = async (
|
|
|
15
21
|
console.log('🔹 Audience:', audience);
|
|
16
22
|
console.log('🔹 Issuer:', issuer);
|
|
17
23
|
|
|
18
|
-
if (!jwtSecret)
|
|
24
|
+
if (!jwtSecret)
|
|
25
|
+
throw new Error('JWT Secret is not defined in the environment');
|
|
19
26
|
|
|
20
27
|
try {
|
|
21
28
|
// ✅ Detect if token is from Google OAuth (ID Token)
|
|
22
|
-
const decodedHeader =
|
|
23
|
-
Buffer.from(token.split('.')[0], 'base64').toString('utf8')
|
|
24
|
-
);
|
|
29
|
+
const decodedHeader = base64UrlDecode(token.split('.')[0]);
|
|
25
30
|
|
|
26
31
|
console.log('🔍 Decoded JWT Header:', decodedHeader);
|
|
27
32
|
|
|
@@ -66,7 +71,7 @@ export const verifyToken = async (
|
|
|
66
71
|
|
|
67
72
|
return {
|
|
68
73
|
userId: payload.sub, // Google User ID
|
|
69
|
-
email: payload.email as string || undefined, // Email might be missing
|
|
74
|
+
email: (payload.email as string) || undefined, // Email might be missing
|
|
70
75
|
};
|
|
71
76
|
} else {
|
|
72
77
|
console.log('🔹 Regular JWT Token Detected');
|
|
@@ -94,4 +99,4 @@ export const verifyToken = async (
|
|
|
94
99
|
console.error('❌ Token Verification Failed:', err.message);
|
|
95
100
|
throw new Error('Invalid or expired token');
|
|
96
101
|
}
|
|
97
|
-
};
|
|
102
|
+
};
|