Skip to content

Commit

Permalink
redirectTo absolute url
Browse files Browse the repository at this point in the history
  • Loading branch information
pogseal committed Jan 9, 2024
1 parent b7e670b commit 449a66c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const loader = async ({
theme: getTheme(request) ?? hints.theme,
},
sitePath: request.url,
hostname,
subDomain,
toast,
locale,
Expand Down
7 changes: 5 additions & 2 deletions app/routes/_auth+/components/LoggedOutMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { LoggedOut } from "./LoggedOut";
export const LoggedOutMobile = () => {
const location = useLocation();
const { t } = useTranslation(["site", "auth"]);
const { loginPath, joinPath } = useRouteLoaderData("root") as {
const { hostname, loginPath, joinPath } = useRouteLoaderData("root") as {
hostname: string;
loginPath: string;
joinPath: string;
};
Expand All @@ -32,7 +33,9 @@ export const LoggedOutMobile = () => {
className="dark:bg-dark400 flex h-10 w-full items-center justify-center
rounded-full border border-zinc-200 bg-zinc-100 text-center text-sm
font-bold dark:border-zinc-600"
to={`${loginPath}/login?redirectTo=${location.pathname}`}
to={`${loginPath}?redirectTo=https://${
hostname + location.pathname
}`}
>
{t("login.action", { ns: "auth" })}
</Link>
Expand Down
9 changes: 7 additions & 2 deletions app/routes/_site+/_components/Column-1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export function ColumnOne({
isUserMenuOpen: boolean;
setUserMenuOpen: Dispatch<SetStateAction<boolean>>;
}) {
const { following, siteSlug, loginPath } = useRouteLoaderData("root") as {
const { hostname, following, siteSlug, loginPath } = useRouteLoaderData(
"root",
) as {
hostname: string;
following: User["sites"];
user: User;
siteSlug: string;
Expand Down Expand Up @@ -89,7 +92,9 @@ export function ColumnOne({
<div className="flex items-center justify-center flex-col gap-3">
<DarkModeToggle />
<Link
to={`${loginPath}?redirectTo=${location.pathname}`}
to={`${loginPath}?redirectTo=https://${
hostname + location.pathname
}`}
className="border-4 border-zinc-300 transition duration-300 active:translate-y-0.5 dark:hover:border-zinc-700
rounded-full flex items-center justify-center w-12 h-12 bg-3 dark:border-zinc-700 hover:border-zinc-200"
>
Expand Down
9 changes: 6 additions & 3 deletions app/routes/_site+/_components/MobileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export function MobileHeader({

const [isFollowerMenuOpen, setFollowerMenuOpen] = useState(false);

const { loginPath, joinPath } = useRouteLoaderData("root") as {
const { hostname, loginPath, joinPath } = useRouteLoaderData("root") as {
hostname: string;
loginPath: string;
joinPath: string;
};
Expand Down Expand Up @@ -96,7 +97,7 @@ export function MobileHeader({
<Link
prefetch="intent"
reloadDocument={true}
to={`${loginPath}/login?redirectTo=/`}
to={`${loginPath}?redirectTo=https://${hostname}`}
className="dark:shadow-zinc-950/40 z-20 flex h-8 items-center justify-center rounded-full bg-zinc-700 px-3.5 text-sm
font-bold text-white shadow-sm dark:bg-white dark:text-black laptop:hidden"
>
Expand All @@ -123,7 +124,9 @@ export function MobileHeader({
className="dark:border-zinc-600 dark:bg-dark450 dark:shadow-zinc-950/40 flex h-8 items-center
justify-center rounded-lg border px-3 text-center bg-white
text-xs font-bold uppercase shadow-sm shadow-zinc-300"
to={`${loginPath}/login?redirectTo=${location.pathname}`}
to={`${loginPath}?redirectTo=https://${
hostname + location.pathname
}`}
>
{t("login.action", { ns: "auth" })}
</Link>
Expand Down
5 changes: 3 additions & 2 deletions app/routes/_site+/_components/SiteHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export function SiteHeader({
const { t } = useTranslation(["site", "auth"]);
const [isPrimaryMenu, setPrimaryMenuOpen] = useState(false);

const { loginPath } = useRouteLoaderData("root") as {
const { loginPath, hostname } = useRouteLoaderData("root") as {
loginPath: string;
hostname: string;
};

return (
Expand Down Expand Up @@ -187,7 +188,7 @@ export function SiteHeader({
<Link
prefetch="intent"
reloadDocument={true}
to={`${loginPath}?redirectTo=/`}
to={`${loginPath}?redirectTo=https://${hostname}`}
className="flex h-9 items-center justify-center rounded-full bg-zinc-700 px-3.5
text-sm font-bold text-white dark:bg-white dark:text-black max-laptop:hidden"
>
Expand Down
4 changes: 1 addition & 3 deletions app/routes/_site+/p+/$p.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,7 @@ export async function action({

const { siteSlug } = await getSiteSlug(request, payload, user);

const url = new URL(request.url).pathname;

if (!user) throw redirect(`${loginPath}?redirectTo=${url}`, { status: 302 });
if (!user) throw redirect(loginPath, { status: 302 });

switch (intent) {
case "updateTitle": {
Expand Down
7 changes: 5 additions & 2 deletions app/routes/_site+/p+/components/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import { initialValue } from "~/routes/_editor+/core/utils";
import { isAdding, isProcessing } from "~/utils/form";

export function Comments({ comments }: { comments: Comment[] }) {
const { user, loginPath } = useRouteLoaderData("root") as {
const { user, loginPath, hostname } = useRouteLoaderData("root") as {
user: User;
loginPath: string;
hostname: string;
};

let location = useLocation();
Expand Down Expand Up @@ -57,7 +58,9 @@ export function Comments({ comments }: { comments: Comment[] }) {
<div className="mb-5 text-sm pl-4 border-l-2 border-color-sub">
<Link
className="underline font-bold pr-1 hover:text-blue-500"
to={`${loginPath}?redirectTo=${location.pathname}`}
to={`${loginPath}?redirectTo=https://${
hostname + location.pathname
}`}
>
Login
</Link>
Expand Down

0 comments on commit 449a66c

Please sign in to comment.