Roberto Vidal commited on
Commit
4df1da4
·
unverified ·
1 Parent(s): 7ebc805

fix: use jose for cloudflare compatibility (#20)

Browse files
packages/bolt/app/lib/.server/sessions.ts CHANGED
@@ -1,8 +1,8 @@
1
  import { createCookieSessionStorage, redirect } from '@remix-run/cloudflare';
 
2
  import { request as doRequest } from '~/lib/fetch';
3
  import { CLIENT_ID, CLIENT_ORIGIN } from '~/lib/constants';
4
  import { logger } from '~/utils/logger';
5
- import { decode } from 'jsonwebtoken';
6
 
7
  const DEV_SESSION_SECRET = import.meta.env.DEV ? 'LZQMrERo3Ewn/AbpSYJ9aw==' : undefined;
8
 
@@ -92,11 +92,9 @@ export async function logout(request: Request, env: Env) {
92
  }
93
 
94
  export function validateAccessToken(access: string) {
95
- const jwtPayload = decode(access);
96
 
97
- const boltEnabled = typeof jwtPayload === 'object' && jwtPayload != null && jwtPayload.bolt === true;
98
-
99
- return boltEnabled;
100
  }
101
 
102
  async function getSession(request: Request, env: Env) {
 
1
  import { createCookieSessionStorage, redirect } from '@remix-run/cloudflare';
2
+ import { decodeJwt } from 'jose';
3
  import { request as doRequest } from '~/lib/fetch';
4
  import { CLIENT_ID, CLIENT_ORIGIN } from '~/lib/constants';
5
  import { logger } from '~/utils/logger';
 
6
 
7
  const DEV_SESSION_SECRET = import.meta.env.DEV ? 'LZQMrERo3Ewn/AbpSYJ9aw==' : undefined;
8
 
 
92
  }
93
 
94
  export function validateAccessToken(access: string) {
95
+ const jwtPayload = decodeJwt(access);
96
 
97
+ return jwtPayload.bolt === true;
 
 
98
  }
99
 
100
  async function getSession(request: Request, env: Env) {
packages/bolt/package.json CHANGED
@@ -48,7 +48,7 @@
48
  "framer-motion": "^11.2.12",
49
  "isbot": "^4.1.0",
50
  "istextorbinary": "^9.5.0",
51
- "jsonwebtoken": "^9.0.2",
52
  "nanostores": "^0.10.3",
53
  "react": "^18.2.0",
54
  "react-dom": "^18.2.0",
@@ -65,7 +65,6 @@
65
  "@cloudflare/workers-types": "^4.20240620.0",
66
  "@remix-run/dev": "^2.10.0",
67
  "@types/diff": "^5.2.1",
68
- "@types/jsonwebtoken": "^9.0.6",
69
  "@types/react": "^18.2.20",
70
  "@types/react-dom": "^18.2.7",
71
  "fast-glob": "^3.3.2",
 
48
  "framer-motion": "^11.2.12",
49
  "isbot": "^4.1.0",
50
  "istextorbinary": "^9.5.0",
51
+ "jose": "^5.6.3",
52
  "nanostores": "^0.10.3",
53
  "react": "^18.2.0",
54
  "react-dom": "^18.2.0",
 
65
  "@cloudflare/workers-types": "^4.20240620.0",
66
  "@remix-run/dev": "^2.10.0",
67
  "@types/diff": "^5.2.1",
 
68
  "@types/react": "^18.2.20",
69
  "@types/react-dom": "^18.2.7",
70
  "fast-glob": "^3.3.2",
pnpm-lock.yaml CHANGED
@@ -131,9 +131,9 @@ importers:
131
  istextorbinary:
132
  specifier: ^9.5.0
133
  version: 9.5.0
134
- jsonwebtoken:
135
- specifier: ^9.0.2
136
- version: 9.0.2
137
  nanostores:
138
  specifier: ^0.10.3
139
  version: 0.10.3
@@ -177,9 +177,6 @@ importers:
177
  '@types/diff':
178
  specifier: ^5.2.1
179
  version: 5.2.1
180
- '@types/jsonwebtoken':
181
- specifier: ^9.0.6
182
- version: 9.0.6
183
  '@types/react':
184
  specifier: ^18.2.20
185
  version: 18.3.3
@@ -1493,9 +1490,6 @@ packages:
1493
  '@types/[email protected]':
1494
  resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
1495
 
1496
- '@types/[email protected]':
1497
- resolution: {integrity: sha512-/5hndP5dCjloafCXns6SZyESp3Ldq7YjH3zwzwczYnjxIT0Fqzk5ROSYVGfFyczIue7IUEj8hkvLbPoLQ18vQw==}
1498
-
1499
  '@types/[email protected]':
1500
  resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==}
1501
 
@@ -1961,9 +1955,6 @@ packages:
1961
  engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
1962
  hasBin: true
1963
 
1964
1965
- resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==}
1966
-
1967
1968
  resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
1969
 
@@ -2372,9 +2363,6 @@ packages:
2372
2373
  resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
2374
 
2375
2376
- resolution: {integrity: sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==}
2377
-
2378
2379
  resolution: {integrity: sha512-ofkXJtn7z0urokN62DI3SBo/5xAtF0rR7tn+S/bSYV79Ka8pTajIIl+fFQ1q88DQEImymmo97M4azY3WX/nUdg==}
2380
  engines: {node: '>=4'}
@@ -3114,6 +3102,9 @@ packages:
3114
  resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==}
3115
  hasBin: true
3116
 
 
 
 
3117
3118
  resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
3119
 
@@ -3174,16 +3165,6 @@ packages:
3174
  resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
3175
  engines: {'0': node >= 0.2.0}
3176
 
3177
3178
- resolution: {integrity: sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==}
3179
- engines: {node: '>=12', npm: '>=6'}
3180
-
3181
3182
- resolution: {integrity: sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==}
3183
-
3184
3185
- resolution: {integrity: sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==}
3186
-
3187
3188
  resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
3189
 
@@ -3230,24 +3211,9 @@ packages:
3230
3231
  resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
3232
 
3233
3234
- resolution: {integrity: sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==}
3235
-
3236
3237
- resolution: {integrity: sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==}
3238
-
3239
3240
- resolution: {integrity: sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==}
3241
-
3242
3243
- resolution: {integrity: sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==}
3244
-
3245
3246
  resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==}
3247
 
3248
3249
- resolution: {integrity: sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==}
3250
-
3251
3252
  resolution: {integrity: sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==}
3253
 
@@ -3257,9 +3223,6 @@ packages:
3257
3258
  resolution: {integrity: sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==}
3259
 
3260
3261
- resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==}
3262
-
3263
3264
  resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==}
3265
 
@@ -6482,10 +6445,6 @@ snapshots:
6482
 
6483
  '@types/[email protected]': {}
6484
 
6485
- '@types/[email protected]':
6486
- dependencies:
6487
- '@types/node': 20.14.9
6488
-
6489
  '@types/[email protected]':
6490
  dependencies:
6491
  '@types/unist': 2.0.10
@@ -7161,8 +7120,6 @@ snapshots:
7161
  node-releases: 2.0.14
7162
  update-browserslist-db: 1.0.16([email protected])
7163
 
7164
7165
-
7166
7167
 
7168
@@ -7564,10 +7521,6 @@ snapshots:
7564
 
7565
7566
 
7567
7568
- dependencies:
7569
- safe-buffer: 5.2.1
7570
-
7571
7572
  dependencies:
7573
  version-range: 4.14.0
@@ -8446,6 +8399,8 @@ snapshots:
8446
 
8447
8448
 
 
 
8449
8450
 
8451
@@ -8493,30 +8448,6 @@ snapshots:
8493
 
8494
8495
 
8496
8497
- dependencies:
8498
- jws: 3.2.2
8499
- lodash.includes: 4.3.0
8500
- lodash.isboolean: 3.0.3
8501
- lodash.isinteger: 4.0.4
8502
- lodash.isnumber: 3.0.3
8503
- lodash.isplainobject: 4.0.6
8504
- lodash.isstring: 4.0.1
8505
- lodash.once: 4.1.1
8506
- ms: 2.1.3
8507
- semver: 7.6.2
8508
-
8509
8510
- dependencies:
8511
- buffer-equal-constant-time: 1.0.1
8512
- ecdsa-sig-formatter: 1.0.11
8513
- safe-buffer: 5.2.1
8514
-
8515
8516
- dependencies:
8517
- jwa: 1.4.1
8518
- safe-buffer: 5.2.1
8519
-
8520
8521
  dependencies:
8522
  json-buffer: 3.0.1
@@ -8555,26 +8486,14 @@ snapshots:
8555
 
8556
8557
 
8558
8559
-
8560
8561
-
8562
8563
-
8564
8565
-
8566
8567
 
8568
8569
-
8570
8571
 
8572
8573
 
8574
8575
 
8576
8577
-
8578
8579
 
8580
 
131
  istextorbinary:
132
  specifier: ^9.5.0
133
  version: 9.5.0
134
+ jose:
135
+ specifier: ^5.6.3
136
+ version: 5.6.3
137
  nanostores:
138
  specifier: ^0.10.3
139
  version: 0.10.3
 
177
  '@types/diff':
178
  specifier: ^5.2.1
179
  version: 5.2.1
 
 
 
180
  '@types/react':
181
  specifier: ^18.2.20
182
  version: 18.3.3
 
1490
  '@types/[email protected]':
1491
  resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
1492
 
 
 
 
1493
  '@types/[email protected]':
1494
  resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==}
1495
 
 
1955
  engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
1956
  hasBin: true
1957
 
 
 
 
1958
1959
  resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
1960
 
 
2363
2364
  resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
2365
 
 
 
 
2366
2367
  resolution: {integrity: sha512-ofkXJtn7z0urokN62DI3SBo/5xAtF0rR7tn+S/bSYV79Ka8pTajIIl+fFQ1q88DQEImymmo97M4azY3WX/nUdg==}
2368
  engines: {node: '>=4'}
 
3102
  resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==}
3103
  hasBin: true
3104
 
3105
3106
+ resolution: {integrity: sha512-1Jh//hEEwMhNYPDDLwXHa2ePWgWiFNNUadVmguAAw2IJ6sj9mNxV5tGXJNqlMkJAybF6Lgw1mISDxTePP/187g==}
3107
+
3108
3109
  resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
3110
 
 
3165
  resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
3166
  engines: {'0': node >= 0.2.0}
3167
 
 
 
 
 
 
 
 
 
 
 
3168
3169
  resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
3170
 
 
3211
3212
  resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
3213
 
 
 
 
 
 
 
 
 
 
 
 
 
3214
3215
  resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==}
3216
 
 
 
 
3217
3218
  resolution: {integrity: sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==}
3219
 
 
3223
3224
  resolution: {integrity: sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==}
3225
 
 
 
 
3226
3227
  resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==}
3228
 
 
6445
 
6446
  '@types/[email protected]': {}
6447
 
 
 
 
 
6448
  '@types/[email protected]':
6449
  dependencies:
6450
  '@types/unist': 2.0.10
 
7120
  node-releases: 2.0.14
7121
  update-browserslist-db: 1.0.16([email protected])
7122
 
 
 
7123
7124
 
7125
 
7521
 
7522
7523
 
 
 
 
 
7524
7525
  dependencies:
7526
  version-range: 4.14.0
 
8399
 
8400
8401
 
8402
8403
+
8404
8405
 
8406
 
8448
 
8449
8450
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8451
8452
  dependencies:
8453
  json-buffer: 3.0.1
 
8486
 
8487
8488
 
 
 
 
 
 
 
 
 
8489
8490
 
 
 
8491
8492
 
8493
8494
 
8495
8496
 
 
 
8497
8498
 
8499