mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 19:21:39 +10:00
fix: preserve params when you are not signed in
This commit is contained in:
@ -20,6 +20,8 @@ export function meta() {
|
||||
|
||||
export async function loader({ request }: Route.LoaderArgs) {
|
||||
const { isAuthenticated } = await getOptionalSession(request);
|
||||
const url = new URL(request.url);
|
||||
const redirectParam = url.searchParams.get('redirect');
|
||||
|
||||
// SSR env variables.
|
||||
const isGoogleSSOEnabled = IS_GOOGLE_SSO_ENABLED;
|
||||
@ -27,6 +29,9 @@ export async function loader({ request }: Route.LoaderArgs) {
|
||||
const oidcProviderLabel = OIDC_PROVIDER_LABEL;
|
||||
|
||||
if (isAuthenticated) {
|
||||
if (redirectParam) {
|
||||
throw redirect(redirectParam);
|
||||
}
|
||||
throw redirect('/');
|
||||
}
|
||||
|
||||
@ -34,11 +39,12 @@ export async function loader({ request }: Route.LoaderArgs) {
|
||||
isGoogleSSOEnabled,
|
||||
isOIDCSSOEnabled,
|
||||
oidcProviderLabel,
|
||||
redirectTo: redirectParam,
|
||||
};
|
||||
}
|
||||
|
||||
export default function SignIn({ loaderData }: Route.ComponentProps) {
|
||||
const { isGoogleSSOEnabled, isOIDCSSOEnabled, oidcProviderLabel } = loaderData;
|
||||
const { isGoogleSSOEnabled, isOIDCSSOEnabled, oidcProviderLabel, redirectTo } = loaderData;
|
||||
|
||||
return (
|
||||
<div className="w-screen max-w-lg px-4">
|
||||
@ -56,6 +62,7 @@ export default function SignIn({ loaderData }: Route.ComponentProps) {
|
||||
isGoogleSSOEnabled={isGoogleSSOEnabled}
|
||||
isOIDCSSOEnabled={isOIDCSSOEnabled}
|
||||
oidcProviderLabel={oidcProviderLabel}
|
||||
returnTo={redirectTo || undefined}
|
||||
/>
|
||||
|
||||
{env('NEXT_PUBLIC_DISABLE_SIGNUP') !== 'true' && (
|
||||
|
||||
@ -9,7 +9,9 @@ import type { Route } from './+types/billing-redirect';
|
||||
export async function loader({ request }: Route.LoaderArgs) {
|
||||
const session = await getOptionalSession(request);
|
||||
if (!session.isAuthenticated) {
|
||||
throw redirect('/signin');
|
||||
const currentUrl = new URL(request.url);
|
||||
const redirectParam = encodeURIComponent(currentUrl.pathname + currentUrl.search);
|
||||
throw redirect(`/signin?redirect=${redirectParam}`);
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
|
||||
Reference in New Issue
Block a user