@@ -22,55 +22,6 @@ import type {
22
22
} from "./types" ;
23
23
24
24
const BASE64_PREFIX = "base64-" ;
25
- const BASE64_LENGTH_PREFIX = "base64l-" ;
26
- const BASE64_LENGTH_PATTERN = / ^ b a s e 6 4 l - ( [ 0 - 9 a - z ] + ) - ( .+ ) $ / ;
27
-
28
- export function decodeBase64Cookie ( value : string ) {
29
- try {
30
- return stringFromBase64URL ( value ) ;
31
- } catch ( e : any ) {
32
- // if an invalid UTF-8 sequence is encountered, it means that reconstructing the chunkedCookie failed and the cookies don't contain useful information
33
- console . warn (
34
- "@supabase/ssr: Detected stale cookie data that does not decode to a UTF-8 string. Please check your integration with Supabase for bugs. This can cause your users to loose session access." ,
35
- ) ;
36
- return null ;
37
- }
38
- }
39
-
40
- export function decodeCookie ( chunkedCookie : string ) {
41
- let decoded = chunkedCookie ;
42
-
43
- if ( chunkedCookie . startsWith ( BASE64_PREFIX ) ) {
44
- return decodeBase64Cookie ( decoded . substring ( BASE64_PREFIX . length ) ) ;
45
- } else if ( chunkedCookie . startsWith ( BASE64_LENGTH_PREFIX ) ) {
46
- const match = chunkedCookie . match ( BASE64_LENGTH_PATTERN ) ;
47
-
48
- if ( ! match ) {
49
- return null ;
50
- }
51
-
52
- const expectedLength = parseInt ( match [ 1 ] , 36 ) ;
53
-
54
- if ( expectedLength === 0 ) {
55
- return null ;
56
- }
57
-
58
- if ( match [ 2 ] . length !== expectedLength ) {
59
- console . warn (
60
- "@supabase/ssr: Detected stale cookie data. Please check your integration with Supabase for bugs. This can cause your users to loose the session." ,
61
- ) ;
62
- }
63
-
64
- if ( expectedLength <= match [ 2 ] . length ) {
65
- return decodeBase64Cookie ( match [ 2 ] . substring ( 0 , expectedLength ) ) ;
66
- } else {
67
- // data is missing, cannot decode cookie
68
- return null ;
69
- }
70
- }
71
-
72
- return decoded ;
73
- }
74
25
75
26
/**
76
27
* Creates a storage client that handles cookies correctly for browser and
@@ -82,7 +33,7 @@ export function decodeCookie(chunkedCookie: string) {
82
33
*/
83
34
export function createStorageFromOptions (
84
35
options : {
85
- cookieEncoding : "raw" | "base64url" | "base64url+length" ;
36
+ cookieEncoding : "raw" | "base64url" ;
86
37
cookies ?:
87
38
| CookieMethodsBrowser
88
39
| CookieMethodsBrowserDeprecated
@@ -252,7 +203,15 @@ export function createStorageFromOptions(
252
203
return null ;
253
204
}
254
205
255
- return decodeCookie ( chunkedCookie ) ;
206
+ let decoded = chunkedCookie ;
207
+
208
+ if ( chunkedCookie . startsWith ( BASE64_PREFIX ) ) {
209
+ decoded = stringFromBase64URL (
210
+ chunkedCookie . substring ( BASE64_PREFIX . length ) ,
211
+ ) ;
212
+ }
213
+
214
+ return decoded ;
256
215
} ,
257
216
setItem : async ( key : string , value : string ) => {
258
217
const allCookies = await getAll ( [ key ] ) ;
@@ -266,13 +225,6 @@ export function createStorageFromOptions(
266
225
267
226
if ( cookieEncoding === "base64url" ) {
268
227
encoded = BASE64_PREFIX + stringToBase64URL ( value ) ;
269
- } else if ( cookieEncoding === "base64url+length" ) {
270
- encoded = [
271
- BASE64_LENGTH_PREFIX ,
272
- value . length . toString ( 36 ) ,
273
- "-" ,
274
- value ,
275
- ] . join ( "" ) ;
276
228
}
277
229
278
230
const setCookies = createChunks ( key , encoded ) ;
@@ -390,7 +342,18 @@ export function createStorageFromOptions(
390
342
return null ;
391
343
}
392
344
393
- return decodeCookie ( chunkedCookie ) ;
345
+ let decoded = chunkedCookie ;
346
+
347
+ if (
348
+ typeof chunkedCookie === "string" &&
349
+ chunkedCookie . startsWith ( BASE64_PREFIX )
350
+ ) {
351
+ decoded = stringFromBase64URL (
352
+ chunkedCookie . substring ( BASE64_PREFIX . length ) ,
353
+ ) ;
354
+ }
355
+
356
+ return decoded ;
394
357
} ,
395
358
setItem : async ( key : string , value : string ) => {
396
359
// We don't have an `onAuthStateChange` event that can let us know that
@@ -448,7 +411,7 @@ export async function applyServerStorage(
448
411
removedItems : { [ name : string ] : boolean } ;
449
412
} ,
450
413
options : {
451
- cookieEncoding : "raw" | "base64url" | "base64url+length" ;
414
+ cookieEncoding : "raw" | "base64url" ;
452
415
cookieOptions ?: CookieOptions | null ;
453
416
} ,
454
417
) {
@@ -476,13 +439,6 @@ export async function applyServerStorage(
476
439
477
440
if ( cookieEncoding === "base64url" ) {
478
441
encoded = BASE64_PREFIX + stringToBase64URL ( encoded ) ;
479
- } else if ( cookieEncoding === "base64url+length" ) {
480
- encoded = [
481
- BASE64_LENGTH_PREFIX ,
482
- encoded . length . toString ( 36 ) ,
483
- "-" ,
484
- stringToBase64URL ( encoded ) ,
485
- ] . join ( "" ) ;
486
442
}
487
443
488
444
const chunks = createChunks ( itemName , encoded ) ;
0 commit comments