@thinkingcat/auth-utils 2.0.13 → 2.0.15
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 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/nextauth/callbacks.d.ts +1 -0
- package/dist/nextauth/callbacks.js +2 -0
- package/dist/nextauth/session.js +1 -0
- package/dist/utils/device-id.d.ts +45 -0
- package/dist/utils/device-id.js +89 -0
- package/package.json +1 -1
package/dist/core/jwt.js
CHANGED
|
@@ -113,6 +113,8 @@ function createNextAuthJWT(payload, serviceId) {
|
|
|
113
113
|
jwt.accessTokenExpires = payload.accessTokenExpires;
|
|
114
114
|
if (payload.serviceId)
|
|
115
115
|
jwt.serviceId = payload.serviceId;
|
|
116
|
+
if (payload.deviceId)
|
|
117
|
+
jwt.deviceId = payload.deviceId;
|
|
116
118
|
return jwt;
|
|
117
119
|
}
|
|
118
120
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './utils/server';
|
|
|
5
5
|
export * from './utils/redirect';
|
|
6
6
|
export * from './utils/path';
|
|
7
7
|
export * from './utils/license';
|
|
8
|
+
export * from './utils/device-id';
|
|
8
9
|
export * from './core/jwt';
|
|
9
10
|
export * from './core/cookies';
|
|
10
11
|
export * from './core/auth-response';
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./utils/server"), exports);
|
|
|
21
21
|
__exportStar(require("./utils/redirect"), exports);
|
|
22
22
|
__exportStar(require("./utils/path"), exports);
|
|
23
23
|
__exportStar(require("./utils/license"), exports);
|
|
24
|
+
__exportStar(require("./utils/device-id"), exports);
|
|
24
25
|
__exportStar(require("./core/jwt"), exports);
|
|
25
26
|
__exportStar(require("./core/cookies"), exports);
|
|
26
27
|
__exportStar(require("./core/auth-response"), exports);
|
|
@@ -55,6 +55,7 @@ function createInitialJWTToken(token, user, account) {
|
|
|
55
55
|
decryptedEmail: user.decryptedEmail ?? undefined,
|
|
56
56
|
decryptedPhone: user.decryptedPhone ?? undefined,
|
|
57
57
|
refreshToken: user.refreshToken ?? undefined,
|
|
58
|
+
deviceId: user.deviceId ?? undefined,
|
|
58
59
|
accessTokenExpires: Date.now() + (15 * 60 * 1000),
|
|
59
60
|
serviceId: account?.serviceId ?? undefined,
|
|
60
61
|
};
|
|
@@ -132,6 +133,7 @@ async function handleJWTCallback(token, user, account, options) {
|
|
|
132
133
|
return {
|
|
133
134
|
...newJWT,
|
|
134
135
|
refreshToken,
|
|
136
|
+
deviceId: newJWT.deviceId || token.deviceId, // Preserve deviceId
|
|
135
137
|
accessTokenExpires: Date.now() + (15 * 60 * 1000),
|
|
136
138
|
};
|
|
137
139
|
}
|
package/dist/nextauth/session.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device ID 관리 유틸리티
|
|
3
|
+
* 브라우저별로 고유한 ID를 생성하고 localStorage에 저장
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 현재 기기의 고유 ID를 가져옵니다.
|
|
7
|
+
* localStorage에 저장된 ID가 있으면 반환하고, 없으면 새로 생성합니다.
|
|
8
|
+
*
|
|
9
|
+
* @param storageKey - localStorage 키 (기본값: 'device_id')
|
|
10
|
+
* @returns {string} 기기 고유 ID
|
|
11
|
+
*/
|
|
12
|
+
export declare function getDeviceId(storageKey?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 새로운 기기 ID를 생성합니다.
|
|
15
|
+
* 형식: {8-char-random} (예: a3f9k2m1)
|
|
16
|
+
*
|
|
17
|
+
* @returns {string} 생성된 기기 ID
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateDeviceId(): string;
|
|
20
|
+
/**
|
|
21
|
+
* 현재 기기 ID를 삭제합니다.
|
|
22
|
+
* 주로 테스트나 디버깅 용도로 사용
|
|
23
|
+
*
|
|
24
|
+
* @param storageKey - localStorage 키 (기본값: 'device_id')
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearDeviceId(storageKey?: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* 기기 정보를 수집합니다 (선택적)
|
|
29
|
+
* 더 정교한 fingerprinting이 필요한 경우 사용
|
|
30
|
+
*
|
|
31
|
+
* @returns {object} 기기 정보
|
|
32
|
+
*/
|
|
33
|
+
export declare function getDeviceInfo(): {
|
|
34
|
+
userAgent?: undefined;
|
|
35
|
+
language?: undefined;
|
|
36
|
+
platform?: undefined;
|
|
37
|
+
screenResolution?: undefined;
|
|
38
|
+
timezone?: undefined;
|
|
39
|
+
} | {
|
|
40
|
+
userAgent: any;
|
|
41
|
+
language: any;
|
|
42
|
+
platform: any;
|
|
43
|
+
screenResolution: string;
|
|
44
|
+
timezone: string;
|
|
45
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Device ID 관리 유틸리티
|
|
4
|
+
* 브라우저별로 고유한 ID를 생성하고 localStorage에 저장
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getDeviceId = getDeviceId;
|
|
8
|
+
exports.generateDeviceId = generateDeviceId;
|
|
9
|
+
exports.clearDeviceId = clearDeviceId;
|
|
10
|
+
exports.getDeviceInfo = getDeviceInfo;
|
|
11
|
+
/**
|
|
12
|
+
* 현재 기기의 고유 ID를 가져옵니다.
|
|
13
|
+
* localStorage에 저장된 ID가 있으면 반환하고, 없으면 새로 생성합니다.
|
|
14
|
+
*
|
|
15
|
+
* @param storageKey - localStorage 키 (기본값: 'device_id')
|
|
16
|
+
* @returns {string} 기기 고유 ID
|
|
17
|
+
*/
|
|
18
|
+
function getDeviceId(storageKey = 'device_id') {
|
|
19
|
+
// 서버 사이드에서는 빈 문자열 반환
|
|
20
|
+
if (typeof globalThis.window === 'undefined') {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
// localStorage에서 기존 ID 확인
|
|
25
|
+
const storage = globalThis.localStorage;
|
|
26
|
+
let deviceId = storage?.getItem(storageKey);
|
|
27
|
+
if (!deviceId) {
|
|
28
|
+
// 없으면 새로 생성
|
|
29
|
+
deviceId = generateDeviceId();
|
|
30
|
+
storage?.setItem(storageKey, deviceId);
|
|
31
|
+
console.log(`[DeviceID] New device ID generated: ${deviceId}`);
|
|
32
|
+
}
|
|
33
|
+
return deviceId;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// localStorage 접근 실패 시 (프라이빗 모드 등)
|
|
37
|
+
console.warn('[DeviceID] Failed to access localStorage:', error);
|
|
38
|
+
return generateDeviceId();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 새로운 기기 ID를 생성합니다.
|
|
43
|
+
* 형식: {8-char-random} (예: a3f9k2m1)
|
|
44
|
+
*
|
|
45
|
+
* @returns {string} 생성된 기기 ID
|
|
46
|
+
*/
|
|
47
|
+
function generateDeviceId() {
|
|
48
|
+
// 8자리 랜덤 문자열 생성
|
|
49
|
+
return Math.random().toString(36).substring(2, 10);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 현재 기기 ID를 삭제합니다.
|
|
53
|
+
* 주로 테스트나 디버깅 용도로 사용
|
|
54
|
+
*
|
|
55
|
+
* @param storageKey - localStorage 키 (기본값: 'device_id')
|
|
56
|
+
*/
|
|
57
|
+
function clearDeviceId(storageKey = 'device_id') {
|
|
58
|
+
if (typeof globalThis.window === 'undefined') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const storage = globalThis.localStorage;
|
|
63
|
+
storage?.removeItem(storageKey);
|
|
64
|
+
console.log('[DeviceID] Device ID cleared');
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.warn('[DeviceID] Failed to clear device ID:', error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 기기 정보를 수집합니다 (선택적)
|
|
72
|
+
* 더 정교한 fingerprinting이 필요한 경우 사용
|
|
73
|
+
*
|
|
74
|
+
* @returns {object} 기기 정보
|
|
75
|
+
*/
|
|
76
|
+
function getDeviceInfo() {
|
|
77
|
+
if (typeof globalThis.window === 'undefined') {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
const nav = globalThis.navigator;
|
|
81
|
+
const scr = globalThis.screen;
|
|
82
|
+
return {
|
|
83
|
+
userAgent: nav?.userAgent || '',
|
|
84
|
+
language: nav?.language || '',
|
|
85
|
+
platform: nav?.platform || '',
|
|
86
|
+
screenResolution: scr ? `${scr.width}x${scr.height}` : '',
|
|
87
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
88
|
+
};
|
|
89
|
+
}
|
package/package.json
CHANGED