@thinkingcat/auth-utils 2.0.9 → 2.0.11
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/dist/core/jwt.js +2 -2
- package/dist/core/verify.js +3 -3
- package/dist/middleware/handler.js +1 -1
- package/dist/types/index.d.ts +4 -2
- package/package.json +1 -1
package/dist/core/jwt.js
CHANGED
|
@@ -49,7 +49,7 @@ async function verifyToken(accessToken, secret) {
|
|
|
49
49
|
try {
|
|
50
50
|
const secretBytes = new TextEncoder().encode(secret);
|
|
51
51
|
const { payload } = await (0, jose_1.jwtVerify)(accessToken, secretBytes);
|
|
52
|
-
if (payload && typeof payload === 'object' && payload.
|
|
52
|
+
if (payload && typeof payload === 'object' && (payload.id || payload.sub)) {
|
|
53
53
|
return { payload: payload };
|
|
54
54
|
}
|
|
55
55
|
return null;
|
|
@@ -174,7 +174,7 @@ function isValidToken(token) {
|
|
|
174
174
|
return false;
|
|
175
175
|
if (isTokenExpired(token))
|
|
176
176
|
return false;
|
|
177
|
-
if (!token.
|
|
177
|
+
if (!token.id)
|
|
178
178
|
return false;
|
|
179
179
|
return true;
|
|
180
180
|
}
|
package/dist/core/verify.js
CHANGED
|
@@ -19,7 +19,7 @@ async function verifyAndRefreshToken(req, secret, options) {
|
|
|
19
19
|
try {
|
|
20
20
|
const secretBytes = new TextEncoder().encode(secret);
|
|
21
21
|
const { payload } = await (0, jose_1.jwtVerify)(accessToken, secretBytes);
|
|
22
|
-
if (payload && typeof payload === 'object' && payload.
|
|
22
|
+
if (payload && typeof payload === 'object' && (payload.id || payload.sub)) {
|
|
23
23
|
return { isValid: true, payload: payload };
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -44,7 +44,7 @@ async function verifyAndRefreshToken(req, secret, options) {
|
|
|
44
44
|
let payload;
|
|
45
45
|
const secretBytes = new TextEncoder().encode(secret);
|
|
46
46
|
const { payload: tokenPayload } = await (0, jose_1.jwtVerify)(refreshResult.accessToken, secretBytes);
|
|
47
|
-
if (tokenPayload && typeof tokenPayload === 'object' && tokenPayload.
|
|
47
|
+
if (tokenPayload && typeof tokenPayload === 'object' && (tokenPayload.id || tokenPayload.sub)) {
|
|
48
48
|
payload = tokenPayload;
|
|
49
49
|
}
|
|
50
50
|
const { NextResponse: NextResponseClass } = await (0, server_1.getNextServer)();
|
|
@@ -117,7 +117,7 @@ async function verifyAndRefreshTokenWithNextAuth(req, nextAuthToken, secret, opt
|
|
|
117
117
|
try {
|
|
118
118
|
const secretBytes = new TextEncoder().encode(secret);
|
|
119
119
|
const { payload } = await (0, jose_1.jwtVerify)(accessToken, secretBytes);
|
|
120
|
-
if (payload && typeof payload === 'object' && payload.
|
|
120
|
+
if (payload && typeof payload === 'object' && (payload.id || payload.sub)) {
|
|
121
121
|
hasValidAccessToken = true;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -198,7 +198,7 @@ async function handleMiddleware(req, config, options) {
|
|
|
198
198
|
const ssoBaseURL = options.ssoBaseURL;
|
|
199
199
|
return await (0, redirect_js_1.redirectToSSOLogin)(req, serviceId, ssoBaseURL);
|
|
200
200
|
}
|
|
201
|
-
if (!finalToken.role || !finalToken.
|
|
201
|
+
if (!finalToken.role || !finalToken.id) {
|
|
202
202
|
const ssoBaseURL = options.ssoBaseURL;
|
|
203
203
|
return await (0, redirect_js_1.redirectToSSOLogin)(req, serviceId, ssoBaseURL);
|
|
204
204
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface ResponseLike {
|
|
|
14
14
|
export interface ServiceInfo {
|
|
15
15
|
serviceId: string;
|
|
16
16
|
role: string;
|
|
17
|
+
joinedAt: string;
|
|
18
|
+
lastAccessAt?: string;
|
|
17
19
|
expiredAt?: string;
|
|
18
20
|
status: string;
|
|
19
21
|
isFree?: boolean;
|
|
@@ -59,8 +61,8 @@ export interface SSORegisterResponse {
|
|
|
59
61
|
export interface JWTPayload {
|
|
60
62
|
sub?: string;
|
|
61
63
|
id?: string;
|
|
62
|
-
email
|
|
63
|
-
name
|
|
64
|
+
email?: string | null;
|
|
65
|
+
name?: string | null;
|
|
64
66
|
role?: string;
|
|
65
67
|
iat?: number;
|
|
66
68
|
exp?: number;
|
package/package.json
CHANGED