Files
Homarr/packages/auth/redirect.ts
Meier Lukas c4c4d41e4d feat: add support for app url variables (#915)
* feat: add support for app url variables

* fix: test not working

* fix: format issue
2024-08-06 21:43:12 +02:00

22 lines
646 B
TypeScript

import type { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
import { extractBaseUrlFromHeaders } from "@homarr/common";
/**
* The redirect_uri is constructed to work behind a reverse proxy. It is constructed from the headers x-forwarded-proto and x-forwarded-host.
* @param headers
* @param pathname
* @returns
*/
export const createRedirectUri = (headers: ReadonlyHeaders | null, pathname: string) => {
if (!headers) {
return pathname;
}
const baseUrl = extractBaseUrlFromHeaders(headers);
const path = pathname.startsWith("/") ? pathname : `/${pathname}`;
return `${baseUrl}${path}`;
};