Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a console warning if writing to cookies doesn't work #260

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [20.1.1] - 2024-07-13

### Changes

- Added a warning if the SDK can't save to cookies to help people notice/debug these issues faster.

## [20.1.0] - 2024-05-31

### Changes
Expand Down
2 changes: 1 addition & 1 deletion bundle/bundle.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion lib/build/fetch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/ts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ async function saveTokensFromHeaders(response: Response) {
}
}

let successfullySavedToCookies: boolean | undefined = undefined;

export async function saveLastAccessTokenUpdate() {
logDebugMessage("saveLastAccessTokenUpdate: called");

Expand All @@ -813,6 +815,16 @@ export async function saveLastAccessTokenUpdate() {
logDebugMessage("saveLastAccessTokenUpdate: setting " + now);
await storeInCookies(LAST_ACCESS_TOKEN_UPDATE, now, Number.MAX_SAFE_INTEGER);

if (successfullySavedToCookies === undefined) {
successfullySavedToCookies = (await getFromCookies(LAST_ACCESS_TOKEN_UPDATE)) === now;
}

if (successfullySavedToCookies === false) {
console.warn(
"Saving to cookies was not successful, this indicates a configuration error or the browser preventing us from writing the cookies (e.g.: incognito mode)."
);
}

// We clear the sIRTFrontend cookie
// We are handling this as a special case here because we want to limit the scope of legacy code
await storeInCookies("sIRTFrontend", "", 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const package_version = "20.1.0";
export const package_version = "20.1.1";

export const supported_fdi = ["1.16", "1.17", "1.18", "1.19", "2.0", "3.0"];
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-website",
"version": "20.1.0",
"version": "20.1.1",
"description": "frontend sdk for website to be used for auth solution.",
"main": "index.js",
"dependencies": {
Expand Down
37 changes: 37 additions & 0 deletions test/interception.basic1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,43 @@ addTestCases((name, transferMethod, setupFunc, setupArgs = []) => {
assert.strictEqual(cookies.length, 0);
});

it("test warnings when cookie writes are not successful", async function () {
await startST(3);
await setup({
// enableDebugLogs: true,
disableCookies: true
});
const logs = [];
page.on("console", c => logs.push(c.text()));
await page.evaluate(async () => {
await new Promise(res => setTimeout(res, 5000));
const userId = "testing-supertokens-website";

const loginResponse = await toTest({
url: `${BASE_URL}/login`,
method: "post",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({ userId })
});

assert.strictEqual(loginResponse.responseText, userId);
});
assert(logs.filter(str => str.includes("the server responded with a status of 401")).length, 1);
assert(
logs.some(str =>
str.includes(
"Saving to cookies was not successful, this indicates a configuration error or the browser preventing us from writing the cookies (e.g.: incognito mode)."
)
)
);

const cookies = await page.cookies();
assert.strictEqual(cookies.length, 0);
});

it("test rid is there", async function () {
await startST(3);
await setup();
Expand Down
31 changes: 31 additions & 0 deletions test/interception.testgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module.exports.addGenericTestCases = function (getTestCases) {
"fetch using " + tokenTransferMethod,
tokenTransferMethod,
(config, tokenTransferMethod) => {
if (config.disableCookies) {
config.cookieHandler = () => ({
setCookie: () => Promise.resolve(),
getCookie: () => Promise.resolve("")
});
}
let overrideFunctions = [];
if (config.override) {
for (const reqOverride of config.override) {
Expand Down Expand Up @@ -62,6 +68,12 @@ module.exports.addGenericTestCases = function (getTestCases) {
"XHR using " + tokenTransferMethod,
tokenTransferMethod,
(config, tokenTransferMethod) => {
if (config.disableCookies) {
config.cookieHandler = () => ({
setCookie: () => Promise.resolve(),
getCookie: () => Promise.resolve("")
});
}
let overrideFunctions = [];
if (config.override) {
for (const reqOverride of config.override) {
Expand Down Expand Up @@ -149,6 +161,12 @@ module.exports.addGenericTestCases = function (getTestCases) {
"axios with axios interceptor using " + tokenTransferMethod,
tokenTransferMethod,
(config, tokenTransferMethod) => {
if (config.disableCookies) {
config.cookieHandler = () => ({
setCookie: () => Promise.resolve(),
getCookie: () => Promise.resolve("")
});
}
let overrideFunctions = [];
if (config.override) {
for (const reqOverride of config.override) {
Expand Down Expand Up @@ -226,6 +244,12 @@ module.exports.addGenericTestCases = function (getTestCases) {
"axios using " + tokenTransferMethod,
tokenTransferMethod,
(config, tokenTransferMethod) => {
if (config.disableCookies) {
config.cookieHandler = () => ({
setCookie: () => Promise.resolve(),
getCookie: () => Promise.resolve("")
});
}
let overrideFunctions = [];
if (config.override) {
for (const reqOverride of config.override) {
Expand Down Expand Up @@ -300,6 +324,13 @@ module.exports.addGenericTestCases = function (getTestCases) {
async (config, tokenTransferMethod) => {
await loadAngular();

if (config.disableCookies) {
config.cookieHandler = () => ({
setCookie: () => Promise.resolve(),
getCookie: () => Promise.resolve("")
});
}

let overrideFunctions = [];
if (config.override) {
for (const reqOverride of config.override) {
Expand Down
Loading