@supabase/ssr
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -40,5 +40,5 @@ import * as _supabase_supabase_js from '@supabase/supabase-js'; | ||
declare function createChunks(key: string, value: string, chunkSize?: number): Chunk[]; | ||
declare function combineChunks(key: string, retrieveChunk?: (name: string) => string | null | undefined): string | null; | ||
declare function deleteChunks(key: string, retrieveChunk?: (name: string) => string | null | undefined, removeChunk?: (name: string) => void): void; | ||
declare function combineChunks(key: string, retrieveChunk: (name: string) => Promise<string | null | undefined> | string | null | undefined): Promise<string | undefined>; | ||
declare function deleteChunks(key: string, retrieveChunk: (name: string) => Promise<string | null | undefined> | string | null | undefined, removeChunk: (name: string) => Promise<void> | void): Promise<void>; | ||
export { CookieMethods, CookieOptions, CookieOptionsWithName, DEFAULT_COOKIE_OPTIONS, combineChunks, createBrowserClient, createChunks, createServerClient, deleteChunks, isBrowser }; |
@@ -72,9 +72,4 @@ "use strict"; | ||
} | ||
function combineChunks(key, retrieveChunk = () => { | ||
return null; | ||
}) { | ||
const value = retrieveChunk(key); | ||
if (key.endsWith("-code-verifier") && value) { | ||
return value; | ||
} | ||
async function combineChunks(key, retrieveChunk) { | ||
const value = await retrieveChunk(key); | ||
if (value) { | ||
@@ -86,3 +81,3 @@ return value; | ||
const chunkName = `${key}.${i}`; | ||
const chunk = retrieveChunk(chunkName); | ||
const chunk = await retrieveChunk(chunkName); | ||
if (!chunk) { | ||
@@ -93,11 +88,10 @@ break; | ||
} | ||
return values.length ? values.join("") : null; | ||
if (values.length > 0) { | ||
return values.join(""); | ||
} | ||
} | ||
function deleteChunks(key, retrieveChunk = () => { | ||
return null; | ||
}, removeChunk = () => { | ||
}) { | ||
const value = retrieveChunk(key); | ||
async function deleteChunks(key, retrieveChunk, removeChunk) { | ||
const value = await retrieveChunk(key); | ||
if (value) { | ||
removeChunk(key); | ||
await removeChunk(key); | ||
return; | ||
@@ -107,7 +101,7 @@ } | ||
const chunkName = `${key}.${i}`; | ||
const chunk = retrieveChunk(chunkName); | ||
const chunk = await retrieveChunk(chunkName); | ||
if (!chunk) { | ||
break; | ||
} | ||
removeChunk(chunkName); | ||
await removeChunk(chunkName); | ||
} | ||
@@ -139,3 +133,3 @@ } | ||
headers: { | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.5"}` | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.6"}` | ||
} | ||
@@ -150,41 +144,71 @@ }, | ||
getItem: async (key) => { | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(key); | ||
} | ||
if (isBrowser()) { | ||
const cookie = (0, import_cookie2.parse)(document.cookie); | ||
return cookie[key]; | ||
} | ||
const chunkedCookie = await combineChunks(key, async (chunkName) => { | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(chunkName); | ||
} | ||
if (isBrowser()) { | ||
const cookie = (0, import_cookie2.parse)(document.cookie); | ||
return cookie[chunkName]; | ||
} | ||
}); | ||
return chunkedCookie; | ||
}, | ||
setItem: async (key, value) => { | ||
if (typeof cookies.set === "function") { | ||
return await cookies.set(key, value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} | ||
if (isBrowser()) { | ||
document.cookie = (0, import_cookie2.serialize)(key, value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} | ||
const chunks = await createChunks(key, value); | ||
await Promise.all( | ||
chunks.map(async (chunk) => { | ||
if (typeof cookies.set === "function") { | ||
await cookies.set(chunk.name, chunk.value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} else { | ||
if (isBrowser()) { | ||
document.cookie = (0, import_cookie2.serialize)(chunk.name, chunk.value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} | ||
} | ||
}) | ||
); | ||
}, | ||
removeItem: async (key) => { | ||
if (typeof cookies.remove === "function") { | ||
return await cookies.remove(key, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: 0 | ||
}); | ||
if (typeof cookies.remove === "function" && typeof cookies.get !== "function") { | ||
console.log( | ||
"Removing chunked cookie without a `get` method is not supported.\n\n When you call the `createBrowserClient` function from the `@supabase/ssr` package, make sure you declare both a `get` and `remove` method on the `cookies` object.\n\nhttps://supabase.com/docs/guides/auth/server-side/creating-a-client" | ||
); | ||
return; | ||
} | ||
if (isBrowser()) { | ||
document.cookie = (0, import_cookie2.serialize)(key, "", { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: 0 | ||
}); | ||
} | ||
await deleteChunks( | ||
key, | ||
async (chunkName) => { | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(chunkName); | ||
} | ||
if (isBrowser()) { | ||
const documentCookies = (0, import_cookie2.parse)(document.cookie); | ||
return documentCookies[chunkName]; | ||
} | ||
}, | ||
async (chunkName) => { | ||
if (typeof cookies.remove === "function") { | ||
await cookies.remove(chunkName, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: 0 | ||
}); | ||
} else { | ||
if (isBrowser()) { | ||
document.cookie = (0, import_cookie2.serialize)(chunkName, "", { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: 0 | ||
}); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
@@ -233,3 +257,3 @@ } | ||
headers: { | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.5"}` | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.6"}` | ||
} | ||
@@ -244,19 +268,47 @@ }, | ||
getItem: async (key) => { | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(key); | ||
} | ||
const chunkedCookie = await combineChunks(key, async (chunkName) => { | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(chunkName); | ||
} | ||
}); | ||
return chunkedCookie; | ||
}, | ||
setItem: async (key, value) => { | ||
if (typeof cookies.set === "function") { | ||
await cookies.set(key, value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} | ||
const chunks = createChunks(key, value); | ||
await Promise.all( | ||
chunks.map(async (chunk) => { | ||
if (typeof cookies.set === "function") { | ||
await cookies.set(chunk.name, chunk.value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} | ||
}) | ||
); | ||
}, | ||
removeItem: async (key) => { | ||
if (typeof cookies.remove === "function") { | ||
await cookies.remove(key, { ...DEFAULT_COOKIE_OPTIONS, ...cookieOptions, maxAge: 0 }); | ||
if (typeof cookies.remove === "function" && typeof cookies.get !== "function") { | ||
console.log( | ||
"Removing chunked cookie without a `get` method is not supported.\n\n When you call the `createServerClient` function from the `@supabase/ssr` package, make sure you declare both a `get` and `remove` method on the `cookies` object.\n\nhttps://supabase.com/docs/guides/auth/server-side/creating-a-client" | ||
); | ||
return; | ||
} | ||
deleteChunks( | ||
key, | ||
async (chunkName) => { | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(chunkName); | ||
} | ||
}, | ||
async (chunkName) => { | ||
if (typeof cookies.remove === "function") { | ||
return await cookies.remove(chunkName, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: 0 | ||
}); | ||
} | ||
} | ||
); | ||
} | ||
@@ -263,0 +315,0 @@ } |
{ | ||
"name": "@supabase/ssr", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60009
641