@tpzdsp/next-toolkit 1.9.1 → 1.9.3
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 +5 -1
- package/src/http/constants.ts +1 -0
- package/src/utils/auth.ts +1 -1
- package/src/utils/utils.ts +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tpzdsp/next-toolkit",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"description": "A reusable React component library for Next.js applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -170,6 +170,7 @@
|
|
|
170
170
|
"globals": "^16.3.0",
|
|
171
171
|
"husky": "^9.1.7",
|
|
172
172
|
"jsdom": "^26.1.0",
|
|
173
|
+
"jose": "^6.1.1",
|
|
173
174
|
"jsonwebtoken": "^9.0.2",
|
|
174
175
|
"next": "^15.4.2",
|
|
175
176
|
"ol": "^10.6.1",
|
|
@@ -253,6 +254,9 @@
|
|
|
253
254
|
"geojson": {
|
|
254
255
|
"optional": true
|
|
255
256
|
},
|
|
257
|
+
"jose": {
|
|
258
|
+
"optional": true
|
|
259
|
+
},
|
|
256
260
|
"jsonwebtoken": {
|
|
257
261
|
"optional": true
|
|
258
262
|
},
|
package/src/http/constants.ts
CHANGED
package/src/utils/auth.ts
CHANGED
package/src/utils/utils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jwtVerify } from 'jose';
|
|
2
2
|
import { twMerge } from 'tailwind-merge';
|
|
3
3
|
|
|
4
4
|
import type { Credentials, DecodedJWT } from '../types/auth';
|
|
5
5
|
|
|
6
|
-
export const decodeAuthToken = (token: string): Credentials | null => {
|
|
6
|
+
export const decodeAuthToken = async (token: string): Promise<Credentials | null> => {
|
|
7
7
|
if (!token) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
@@ -16,9 +16,10 @@ export const decodeAuthToken = (token: string): Credentials | null => {
|
|
|
16
16
|
throw new Error('JWT secret not set');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const secretKey = new TextEncoder().encode(secret);
|
|
20
|
+
const { payload } = await jwtVerify(token, secretKey);
|
|
20
21
|
|
|
21
|
-
return { token, user };
|
|
22
|
+
return { token, user: payload as DecodedJWT };
|
|
22
23
|
} catch (error) {
|
|
23
24
|
console.error('Error decoding auth token:', error);
|
|
24
25
|
|