@@ -22,55 +22,6 @@ import type {
2222} from "./types" ;
2323
2424const 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- }
7425
7526/**
7627 * Creates a storage client that handles cookies correctly for browser and
@@ -82,7 +33,7 @@ export function decodeCookie(chunkedCookie: string) {
8233 */
8334export function createStorageFromOptions (
8435 options : {
85- cookieEncoding : "raw" | "base64url" | "base64url+length" ;
36+ cookieEncoding : "raw" | "base64url" ;
8637 cookies ?:
8738 | CookieMethodsBrowser
8839 | CookieMethodsBrowserDeprecated
@@ -252,7 +203,15 @@ export function createStorageFromOptions(
252203 return null ;
253204 }
254205
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 ;
256215 } ,
257216 setItem : async ( key : string , value : string ) => {
258217 const allCookies = await getAll ( [ key ] ) ;
@@ -266,13 +225,6 @@ export function createStorageFromOptions(
266225
267226 if ( cookieEncoding === "base64url" ) {
268227 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 ( "" ) ;
276228 }
277229
278230 const setCookies = createChunks ( key , encoded ) ;
@@ -390,7 +342,18 @@ export function createStorageFromOptions(
390342 return null ;
391343 }
392344
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 ;
394357 } ,
395358 setItem : async ( key : string , value : string ) => {
396359 // We don't have an `onAuthStateChange` event that can let us know that
@@ -448,7 +411,7 @@ export async function applyServerStorage(
448411 removedItems : { [ name : string ] : boolean } ;
449412 } ,
450413 options : {
451- cookieEncoding : "raw" | "base64url" | "base64url+length" ;
414+ cookieEncoding : "raw" | "base64url" ;
452415 cookieOptions ?: CookieOptions | null ;
453416 } ,
454417) {
@@ -476,13 +439,6 @@ export async function applyServerStorage(
476439
477440 if ( cookieEncoding === "base64url" ) {
478441 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 ( "" ) ;
486442 }
487443
488444 const chunks = createChunks ( itemName , encoded ) ;
0 commit comments