Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hard refresh on auth #3305

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions web/src/app/auth/login/EmailPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { usePopup } from "@/components/admin/connectors/Popup";
import { basicLogin, basicSignup } from "@/lib/user";
import { Button } from "@/components/ui/button";
import { Form, Formik } from "formik";
import { useRouter } from "next/navigation";
import * as Yup from "yup";
import { requestEmailVerification } from "../lib";
import { useState } from "react";
Expand All @@ -22,10 +21,8 @@ export function EmailPasswordForm({
referralSource?: string;
nextUrl?: string | null;
}) {
const router = useRouter();
const { popup, setPopup } = usePopup();
const [isWorking, setIsWorking] = useState(false);

return (
<>
{isWorking && <Spinner />}
Expand Down Expand Up @@ -69,9 +66,13 @@ export function EmailPasswordForm({
if (loginResponse.ok) {
if (isSignup && shouldVerify) {
await requestEmailVerification(values.email);
router.push("/auth/waiting-on-verification");
// Use window.location.href to force a full page reload,
// ensuring app re-initializes with the new state (including
// server-side provider values)
window.location.href = "/auth/waiting-on-verification";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comment as to why we're doing this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels "wrong" to do this, so would love to have the justification here to alleviate future confusion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, would it be possible to just do a router.refresh() or similar?

Copy link
Contributor Author

@pablonyx pablonyx Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly router.refresh doesn't trigger server side refresh for providers. Could use specific <Link attributes to trigger full refresh, but we'd need to either move our providers client side or have a global refresh we use for this redirect (which feels less maintainable than just triggering global update here).

} else {
router.push(nextUrl ? encodeURI(nextUrl) : "/");
// See above comment
window.location.href = nextUrl ? encodeURI(nextUrl) : "/";
}
} else {
setIsWorking(false);
Expand Down
Loading