@tpzdsp/next-toolkit 1.9.3 → 1.9.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 +1 -1
- package/src/utils/utils.ts +4 -12
package/package.json
CHANGED
package/src/utils/utils.ts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { decode } from 'jsonwebtoken';
|
|
2
2
|
import { twMerge } from 'tailwind-merge';
|
|
3
3
|
|
|
4
4
|
import type { Credentials, DecodedJWT } from '../types/auth';
|
|
5
5
|
|
|
6
|
-
export const decodeAuthToken =
|
|
6
|
+
export const decodeAuthToken = (token: string): Credentials | null => {
|
|
7
7
|
if (!token) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
try {
|
|
12
|
-
|
|
13
|
-
const secret = process.env.JWT_SECRET;
|
|
12
|
+
const user = decode(token) as unknown as DecodedJWT;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
throw new Error('JWT secret not set');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const secretKey = new TextEncoder().encode(secret);
|
|
20
|
-
const { payload } = await jwtVerify(token, secretKey);
|
|
21
|
-
|
|
22
|
-
return { token, user: payload as DecodedJWT };
|
|
14
|
+
return { token, user };
|
|
23
15
|
} catch (error) {
|
|
24
16
|
console.error('Error decoding auth token:', error);
|
|
25
17
|
|