better logging

This commit is contained in:
Karol Wypchlo 2021-09-29 14:32:56 +02:00
parent 64a750cac0
commit 159f4cc2ca
No known key found for this signature in database
GPG Key ID: C92C016317A964D0
1 changed files with 8 additions and 6 deletions

View File

@ -4,13 +4,15 @@ const isProduction = process.env.NODE_ENV === "production";
export default function authServerSideProps(getServerSideProps) { export default function authServerSideProps(getServerSideProps) {
return function authenticate(context) { return function authenticate(context) {
if (isProduction && (!("ory_kratos_session" in context.req.cookies) || !("skynet-jwt" in context.req.cookies))) { const authCookies = ["ory_kratos_session", "skynet-jwt"];
if ("skynet-jwt" in context.req.cookies) {
console.log(`Cookie skynet-jwt is present but ory_kratos_session is not - redirecting to login`);
}
if ("ory_kratos_session" in context.req.cookies) { if (isProduction && !authCookies.every((cookie) => context.req.cookies[cookie])) {
console.log(`Cookie ory_kratos_session is present but skynet-jwt is not - redirecting to login`); // 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 { return {