add server action proxies

This commit is contained in:
miloschwartz
2025-09-25 17:14:25 -07:00
parent 21f0cd6e3f
commit e555d3c496
9 changed files with 663 additions and 164 deletions

View File

@@ -5,6 +5,8 @@ import ResetPasswordForm from "@app/components/ResetPasswordForm";
import Link from "next/link";
import { cleanRedirect } from "@app/lib/cleanRedirect";
import { getTranslations } from "next-intl/server";
import { internal } from "@app/lib/api";
import { authCookieHeader } from "@app/lib/api/cookies";
export const dynamic = "force-dynamic";
@@ -22,7 +24,19 @@ export default async function Page(props: {
const t = await getTranslations();
if (user) {
redirect("/");
let loggedOut = false;
try {
// log out the user if they are logged in
await internal.post(
"/auth/logout",
undefined,
await authCookieHeader()
);
loggedOut = true;
} catch (e) {}
if (!loggedOut) {
redirect("/");
}
}
let redirectUrl: string | undefined = undefined;
@@ -45,8 +59,8 @@ export default async function Page(props: {
<Link
href={
!searchParams.redirect
? `/auth/signup`
: `/auth/signup?redirect=${redirectUrl}`
? `/auth/login`
: `/auth/login?redirect=${redirectUrl}`
}
className="underline"
>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -29,10 +29,13 @@ export default async function Page(props: {
const getUser = cache(verifySession);
const user = await getUser({ skipCheckVerifyEmail: true });
const setupRes = await internal.get<
let complete = false;
try {
const setupRes = await internal.get<
AxiosResponse<InitialSetupCompleteResponse>
>(`/auth/initial-setup-complete`, await authCookieHeader());
const complete = setupRes.data.data.complete;
>(`/auth/initial-setup-complete`, await authCookieHeader());
complete = setupRes.data.data.complete;
} catch (e) {}
if (!complete) {
redirect("/auth/initial-setup");
}