better logging
This commit is contained in:
parent
64a750cac0
commit
159f4cc2ca
|
@ -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 {
|
||||||
|
|
Reference in New Issue