fix
This commit is contained in:
@@ -24,13 +24,20 @@ export default function LoginPage() {
|
||||
const t = useTranslations("LoginPage");
|
||||
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [redirectTo, setRedirectTo] = useState<string | null>(null);
|
||||
const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<FormData>();
|
||||
|
||||
useEffect(() => {
|
||||
if (!session) {
|
||||
window.location.href = "/api/auth/initiate";
|
||||
router.replace("/api/auth/initiate");
|
||||
}
|
||||
}, [session]);
|
||||
}, [session, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (redirectTo) {
|
||||
router.push(redirectTo);
|
||||
}
|
||||
}, [redirectTo, router]);
|
||||
|
||||
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||
setError(null);
|
||||
@@ -39,16 +46,15 @@ export default function LoginPage() {
|
||||
|
||||
if (!result.success) {
|
||||
if (result.expired) {
|
||||
window.location.href = "/api/auth/initiate";
|
||||
setRedirectTo("/api/auth/initiate");
|
||||
return;
|
||||
}
|
||||
|
||||
setError(result.message ?? null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.redirectURL) {
|
||||
window.location.href = result.redirectURL;
|
||||
setRedirectTo(result.redirectURL);
|
||||
} else {
|
||||
router.push(`/consent?session=${session}`);
|
||||
}
|
||||
@@ -113,9 +119,9 @@ export default function LoginPage() {
|
||||
</FieldGroup>
|
||||
</form>
|
||||
<FieldDescription className="px-6 text-center">
|
||||
{t.rich("noAccountNote", {
|
||||
register: (chunks) => <Link href="/register">{chunks}</Link>
|
||||
})}
|
||||
{t.rich("noAccountNote", {
|
||||
register: (chunks) => <Link href="/register">{chunks}</Link>
|
||||
})}
|
||||
</FieldDescription>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user