@thinkingcat/auth-utils 2.0.3 → 2.0.5
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/middleware/handler.js +0 -34
- package/package.json +1 -1
|
@@ -71,40 +71,6 @@ async function handleMiddleware(req, config, options) {
|
|
|
71
71
|
(0, logger_js_1.debugLog)('handleMiddleware', 'getToken failed', error);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
// Refresh token 체크 - 없으면 모든 인증 쿠키 초기화
|
|
75
|
-
const refreshTokenCookieName = `${cookiePrefix}_refresh_token`;
|
|
76
|
-
const refreshTokenCookie = req.cookies.get(refreshTokenCookieName);
|
|
77
|
-
if (!refreshTokenCookie && req.cookies.getAll().length > 0) {
|
|
78
|
-
(0, logger_js_1.debugLog)('handleMiddleware', `No refresh token found (${refreshTokenCookieName}), clearing all auth cookies`);
|
|
79
|
-
// 인증 관련 쿠키 패턴
|
|
80
|
-
const authCookiePatterns = [
|
|
81
|
-
/^next-auth\./,
|
|
82
|
-
/^__Secure-next-auth\./,
|
|
83
|
-
/_access_token$/,
|
|
84
|
-
/_refresh_token$/,
|
|
85
|
-
/^auth-token$/,
|
|
86
|
-
/^__Secure-auth-token$/,
|
|
87
|
-
];
|
|
88
|
-
// 응답 생성하여 쿠키 삭제
|
|
89
|
-
const response = NextResponseClass.next();
|
|
90
|
-
// 모든 쿠키 확인하고 인증 관련 쿠키 삭제
|
|
91
|
-
req.cookies.getAll().forEach((cookie) => {
|
|
92
|
-
const isAuthCookie = authCookiePatterns.some((pattern) => pattern.test(cookie.name));
|
|
93
|
-
if (isAuthCookie) {
|
|
94
|
-
(0, logger_js_1.debugLog)('handleMiddleware', `Deleting stale cookie: ${cookie.name}`);
|
|
95
|
-
response.cookies.delete(cookie.name);
|
|
96
|
-
// 추가로 만료된 쿠키로 설정
|
|
97
|
-
response.cookies.set(cookie.name, '', {
|
|
98
|
-
expires: new Date(0),
|
|
99
|
-
path: '/',
|
|
100
|
-
secure: isProduction,
|
|
101
|
-
httpOnly: true,
|
|
102
|
-
sameSite: 'lax',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
(0, logger_js_1.debugLog)('handleMiddleware', 'Stale auth cookies cleared');
|
|
107
|
-
}
|
|
108
74
|
const effectiveRole = (0, roles_js_1.getEffectiveRole)(token, serviceId);
|
|
109
75
|
// 1. API 요청 처리
|
|
110
76
|
if (pathname.startsWith('/api/')) {
|