From 159f4cc2caa83a74a92cdba4a2a6b02140025735 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 29 Sep 2021 14:32:56 +0200 Subject: [PATCH] better logging --- .../dashboard/src/services/authServerSideProps.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/dashboard/src/services/authServerSideProps.js b/packages/dashboard/src/services/authServerSideProps.js index bd6839f3..83c848d3 100644 --- a/packages/dashboard/src/services/authServerSideProps.js +++ b/packages/dashboard/src/services/authServerSideProps.js @@ -4,13 +4,15 @@ const isProduction = process.env.NODE_ENV === "production"; export default function authServerSideProps(getServerSideProps) { return function authenticate(context) { - if (isProduction && (!("ory_kratos_session" in context.req.cookies) || !("skynet-jwt" in context.req.cookies))) { - if ("skynet-jwt" in context.req.cookies) { - console.log(`Cookie skynet-jwt is present but ory_kratos_session is not - redirecting to login`); - } + const authCookies = ["ory_kratos_session", "skynet-jwt"]; - if ("ory_kratos_session" in context.req.cookies) { - console.log(`Cookie ory_kratos_session is present but skynet-jwt is not - redirecting to login`); + if (isProduction && !authCookies.every((cookie) => context.req.cookies[cookie])) { + // it is higly unusual that some of the cookies would be set but other would not + if (authCookies.some((cookie) => context.req.cookies[cookie])) { + console.log( + "Unexpected auth cookies state!", + authCookies.map((cookie) => `[${cookie}] is ${context.req.cookies[cookie] ? "set" : "not set"}`) + ); } return {