fix: credentials login not working cause of cookie secure flag not possible for http (#1421)

* fix: credentials login not working cause of cookie secure flag not possible for http

* chore: add missing comment

* fix: lint issue
This commit is contained in:
Meier Lukas
2024-11-04 19:20:19 +01:00
committed by GitHub
parent 97eb4c54e2
commit cf5bcab732
4 changed files with 24 additions and 12 deletions

View File

@@ -5,10 +5,23 @@ import type { SupportedAuthProvider } from "@homarr/definitions";
import { logger } from "@homarr/log";
export const GET = async (req: NextRequest) => {
return await createHandlers(extractProvider(req)).handlers.GET(reqWithTrustedOrigin(req));
return await createHandlers(extractProvider(req), isSecureCookieEnabled(req)).handlers.GET(reqWithTrustedOrigin(req));
};
export const POST = async (req: NextRequest) => {
return await createHandlers(extractProvider(req)).handlers.POST(reqWithTrustedOrigin(req));
return await createHandlers(extractProvider(req), isSecureCookieEnabled(req)).handlers.POST(
reqWithTrustedOrigin(req),
);
};
/**
* wheter to use secure cookies or not, is only supported for https.
* For http it will not add the cookie as it is not considered secure.
* @param req request containing the url
* @returns true if the request is https, false otherwise
*/
const isSecureCookieEnabled = (req: NextRequest): boolean => {
const url = new URL(req.url);
return url.protocol === "https:";
};
/**