@sevenfold/setto-client 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/setto-client.js +43 -12
- package/dist/setto-client.js.map +1 -1
- package/package.json +1 -1
package/dist/setto-client.js
CHANGED
|
@@ -22661,14 +22661,23 @@ function adminRedirectUrl() {
|
|
|
22661
22661
|
}
|
|
22662
22662
|
function authCallbackType() {
|
|
22663
22663
|
const hash = window.location.hash.replace(/^#/, "");
|
|
22664
|
-
if (
|
|
22665
|
-
|
|
22666
|
-
|
|
22664
|
+
if (hash) {
|
|
22665
|
+
const type = new URLSearchParams(hash).get("type");
|
|
22666
|
+
if (type === "invite" || type === "recovery") return type;
|
|
22667
|
+
}
|
|
22668
|
+
const queryType = new URLSearchParams(window.location.search).get("type");
|
|
22669
|
+
if (queryType === "invite" || queryType === "recovery") return queryType;
|
|
22667
22670
|
return null;
|
|
22668
22671
|
}
|
|
22669
|
-
function
|
|
22670
|
-
|
|
22671
|
-
|
|
22672
|
+
function inviteTokenHashFromUrl() {
|
|
22673
|
+
return new URLSearchParams(window.location.search).get("token_hash");
|
|
22674
|
+
}
|
|
22675
|
+
function clearAuthParamsFromUrl() {
|
|
22676
|
+
const url = new URL(window.location.href);
|
|
22677
|
+
url.hash = "";
|
|
22678
|
+
url.searchParams.delete("token_hash");
|
|
22679
|
+
url.searchParams.delete("type");
|
|
22680
|
+
window.history.replaceState(null, "", `${url.pathname}${url.search}`);
|
|
22672
22681
|
}
|
|
22673
22682
|
function AuthGate({ children }) {
|
|
22674
22683
|
const { supabase, session, authLoading } = useSetto();
|
|
@@ -22679,16 +22688,38 @@ function AuthGate({ children }) {
|
|
|
22679
22688
|
const [error, setError] = useState(null);
|
|
22680
22689
|
const [info, setInfo] = useState(null);
|
|
22681
22690
|
const [busy, setBusy] = useState(false);
|
|
22691
|
+
const [activatingInvite, setActivatingInvite] = useState(false);
|
|
22682
22692
|
useEffect(() => {
|
|
22683
|
-
const
|
|
22684
|
-
|
|
22685
|
-
|
|
22693
|
+
const tokenHash = inviteTokenHashFromUrl();
|
|
22694
|
+
const callbackType = authCallbackType();
|
|
22695
|
+
if (!tokenHash || !callbackType) {
|
|
22696
|
+
if (callbackType) setMode("set_password");
|
|
22697
|
+
return;
|
|
22698
|
+
}
|
|
22699
|
+
let cancelled = false;
|
|
22700
|
+
setActivatingInvite(true);
|
|
22701
|
+
void supabase.auth.verifyOtp({ token_hash: tokenHash, type: callbackType }).then(({ error: verifyError }) => {
|
|
22702
|
+
if (cancelled) return;
|
|
22703
|
+
clearAuthParamsFromUrl();
|
|
22704
|
+
if (verifyError) {
|
|
22705
|
+
setError(verifyError.message);
|
|
22706
|
+
setMode("signin");
|
|
22707
|
+
return;
|
|
22708
|
+
}
|
|
22709
|
+
setMode("set_password");
|
|
22710
|
+
}).finally(() => {
|
|
22711
|
+
if (!cancelled) setActivatingInvite(false);
|
|
22712
|
+
});
|
|
22713
|
+
return () => {
|
|
22714
|
+
cancelled = true;
|
|
22715
|
+
};
|
|
22716
|
+
}, [supabase]);
|
|
22686
22717
|
if (authLoading) {
|
|
22687
22718
|
return /* @__PURE__ */ jsx("div", { style: loadingStyle, children: "Laster …" });
|
|
22688
22719
|
}
|
|
22689
22720
|
if (session && mode !== "set_password") return /* @__PURE__ */ jsx(Fragment, { children });
|
|
22690
|
-
if (mode === "set_password" && !session) {
|
|
22691
|
-
return /* @__PURE__ */ jsx("div", { style: loadingStyle, children: authCallbackType() ? "Aktiverer invitasjon …" : "Åpne lenken fra e-posten for å sette passord." });
|
|
22721
|
+
if (mode === "set_password" && !session || activatingInvite) {
|
|
22722
|
+
return /* @__PURE__ */ jsx("div", { style: loadingStyle, children: activatingInvite || authCallbackType() ? "Aktiverer invitasjon …" : "Åpne lenken fra e-posten for å sette passord." });
|
|
22692
22723
|
}
|
|
22693
22724
|
const submitSignIn = async (e) => {
|
|
22694
22725
|
e.preventDefault();
|
|
@@ -22743,7 +22774,7 @@ function AuthGate({ children }) {
|
|
|
22743
22774
|
try {
|
|
22744
22775
|
const { error: updateError } = await supabase.auth.updateUser({ password });
|
|
22745
22776
|
if (updateError) throw updateError;
|
|
22746
|
-
|
|
22777
|
+
clearAuthParamsFromUrl();
|
|
22747
22778
|
const { data: sessionData } = await supabase.auth.getSession();
|
|
22748
22779
|
if (sessionData.session) {
|
|
22749
22780
|
window.location.replace(editModeUrl());
|