Commit fadea1d2 authored by Daniel Gal's avatar Daniel Gal
Browse files

Fixed broken auth flow on unload

parent fda3867b
Pipeline #4022 passed with stage
in 3 minutes and 1 second
import { useState } from "react";
import { useState, useEffect } from "react";
import Cookies from "js-cookie";
//
import Input from "../components/input";
......@@ -11,8 +11,23 @@ import { isServer } from "../lib/api";
export default function Onboarding() {
const [text, setText] = useState("");
const [error, setError] = useState("");
const [done, setDone] = useState(false);
const { revalidate } = useAuth();
// If the user navigates away from (or reloads) the page, logout his user from the auth flow
async function beforeUnload() {
if (!done) {
await api.post("/api/v1/auth/display-name/", {
cancel: true
});
}
}
useEffect(() => {
window.addEventListener("beforeunload", beforeUnload);
return () => window.removeEventListener("beforeunload", beforeUnload);
}, []);
async function handleSubmit(e) {
e.preventDefault();
if (!text) {
......@@ -23,6 +38,7 @@ export default function Onboarding() {
await api.post("/api/v1/auth/display-name/", {
display_name: text
});
setDone(true);
revalidate();
redirect("/");
} catch (e) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment