Skip to content

Commit

Permalink
got login routing working
Browse files Browse the repository at this point in the history
  • Loading branch information
hagen-danswer committed Nov 24, 2024
1 parent ec73a3c commit 27a6575
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
4 changes: 3 additions & 1 deletion web/src/app/auth/login/EmailPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export function EmailPasswordForm({
isSignup = false,
shouldVerify,
referralSource,
nextUrl,
}: {
isSignup?: boolean;
shouldVerify?: boolean;
referralSource?: string;
nextUrl?: string | null;
}) {
const router = useRouter();
const { popup, setPopup } = usePopup();
Expand Down Expand Up @@ -69,7 +71,7 @@ export function EmailPasswordForm({
await requestEmailVerification(values.email);
router.push("/auth/waiting-on-verification");
} else {
router.push("/");
router.push(nextUrl ? encodeURI(nextUrl) : "/");
}
} else {
setIsWorking(false);
Expand Down
21 changes: 13 additions & 8 deletions web/src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const Page = async (props: {
}) => {
const searchParams = await props.searchParams;
const autoRedirectDisabled = searchParams?.disableAutoRedirect === "true";
const nextUrl = Array.isArray(searchParams?.next)
? searchParams?.next[0]
: searchParams?.next || null;

// catch cases where the backend is completely unreachable here
// without try / catch, will just raise an exception and the page
Expand All @@ -37,10 +40,6 @@ const Page = async (props: {
console.log(`Some fetch failed for the login page - ${e}`);
}

const nextUrl = Array.isArray(searchParams?.next)
? searchParams?.next[0]
: searchParams?.next || null;

// simply take the user to the home page if Auth is disabled
if (authTypeMetadata?.authType === "disabled") {
return redirect("/");
Expand Down Expand Up @@ -100,12 +99,15 @@ const Page = async (props: {
<span className="px-4 text-gray-500">or</span>
<div className="flex-grow border-t border-gray-300"></div>
</div>
<EmailPasswordForm shouldVerify={true} />
<EmailPasswordForm shouldVerify={true} nextUrl={nextUrl} />

<div className="flex">
<Text className="mt-4 mx-auto">
Don&apos;t have an account?{" "}
<Link href="/auth/signup" className="text-link font-medium">
<Link
href={`/auth/signup${searchParams?.next ? `?next=${searchParams.next}` : ""}`}
className="text-link font-medium"
>
Create an account
</Link>
</Text>
Expand All @@ -120,11 +122,14 @@ const Page = async (props: {
<LoginText />
</Title>
</div>
<EmailPasswordForm />
<EmailPasswordForm nextUrl={nextUrl} />
<div className="flex">
<Text className="mt-4 mx-auto">
Don&apos;t have an account?{" "}
<Link href="/auth/signup" className="text-link font-medium">
<Link
href={`/auth/signup${searchParams?.next ? `?next=${searchParams.next}` : ""}`}
className="text-link font-medium"
>
Create an account
</Link>
</Text>
Expand Down
19 changes: 17 additions & 2 deletions web/src/app/auth/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ import AuthFlowContainer from "@/components/auth/AuthFlowContainer";
import ReferralSourceSelector from "./ReferralSourceSelector";
import { Separator } from "@/components/ui/separator";

const Page = async () => {
const Page = async ({
searchParams,
}: {
searchParams: { [key: string]: string | string[] | undefined };
}) => {
const nextUrl = Array.isArray(searchParams?.next)
? searchParams?.next[0]
: searchParams?.next || null;

// catch cases where the backend is completely unreachable here
// without try / catch, will just raise an exception and the page
// will not render
Expand Down Expand Up @@ -86,12 +94,19 @@ const Page = async () => {
<EmailPasswordForm
isSignup
shouldVerify={authTypeMetadata?.requiresVerification}
nextUrl={nextUrl}
/>

<div className="flex">
<Text className="mt-4 mx-auto">
Already have an account?{" "}
<Link href="/auth/login" className="text-link font-medium">
<Link
href={{
pathname: "/auth/login",
query: { ...searchParams },
}}
className="text-link font-medium"
>
Log In
</Link>
</Text>
Expand Down

0 comments on commit 27a6575

Please sign in to comment.