mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
feat: clear timeouts
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
"axios": "^1.11.0",
|
"axios": "^1.11.0",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"dompurify": "^3.2.6",
|
|
||||||
"i18next": "^25.4.2",
|
"i18next": "^25.4.2",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"i18next-resources-to-backend": "^1.2.1",
|
"i18next-resources-to-backend": "^1.2.1",
|
||||||
@@ -364,8 +363,6 @@
|
|||||||
|
|
||||||
"@types/react-dom": ["@types/react-dom@19.1.8", "", { "peerDependencies": { "@types/react": "^19.0.0" } }, "sha512-xG7xaBMJCpcK0RpN8jDbAACQo54ycO6h4dSSmgv8+fu6ZIAdANkx/WsawASUjVXYfy+J9AbUpRMNNEsXCDfDBQ=="],
|
"@types/react-dom": ["@types/react-dom@19.1.8", "", { "peerDependencies": { "@types/react": "^19.0.0" } }, "sha512-xG7xaBMJCpcK0RpN8jDbAACQo54ycO6h4dSSmgv8+fu6ZIAdANkx/WsawASUjVXYfy+J9AbUpRMNNEsXCDfDBQ=="],
|
||||||
|
|
||||||
"@types/trusted-types": ["@types/trusted-types@2.0.7", "", {}, "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw=="],
|
|
||||||
|
|
||||||
"@types/unist": ["@types/unist@3.0.3", "", {}, "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q=="],
|
"@types/unist": ["@types/unist@3.0.3", "", {}, "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q=="],
|
||||||
|
|
||||||
"@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.41.0", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.41.0", "@typescript-eslint/type-utils": "8.41.0", "@typescript-eslint/utils": "8.41.0", "@typescript-eslint/visitor-keys": "8.41.0", "graphemer": "^1.4.0", "ignore": "^7.0.0", "natural-compare": "^1.4.0", "ts-api-utils": "^2.1.0" }, "peerDependencies": { "@typescript-eslint/parser": "^8.41.0", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "sha512-8fz6oa6wEKZrhXWro/S3n2eRJqlRcIa6SlDh59FXJ5Wp5XRZ8B9ixpJDcjadHq47hMx0u+HW6SNa6LjJQ6NLtw=="],
|
"@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.41.0", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.41.0", "@typescript-eslint/type-utils": "8.41.0", "@typescript-eslint/utils": "8.41.0", "@typescript-eslint/visitor-keys": "8.41.0", "graphemer": "^1.4.0", "ignore": "^7.0.0", "natural-compare": "^1.4.0", "ts-api-utils": "^2.1.0" }, "peerDependencies": { "@typescript-eslint/parser": "^8.41.0", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "sha512-8fz6oa6wEKZrhXWro/S3n2eRJqlRcIa6SlDh59FXJ5Wp5XRZ8B9ixpJDcjadHq47hMx0u+HW6SNa6LjJQ6NLtw=="],
|
||||||
@@ -476,8 +473,6 @@
|
|||||||
|
|
||||||
"devlop": ["devlop@1.1.0", "", { "dependencies": { "dequal": "^2.0.0" } }, "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA=="],
|
"devlop": ["devlop@1.1.0", "", { "dependencies": { "dequal": "^2.0.0" } }, "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA=="],
|
||||||
|
|
||||||
"dompurify": ["dompurify@3.2.6", "", { "optionalDependencies": { "@types/trusted-types": "^2.0.7" } }, "sha512-/2GogDQlohXPZe6D6NOgQvXLPSYBqIWMnZ8zzOhn09REE4eyAzb+Hed3jhoM9OkuaJ8P6ZGTTVWQKAi8ieIzfQ=="],
|
|
||||||
|
|
||||||
"dunder-proto": ["dunder-proto@1.0.1", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="],
|
"dunder-proto": ["dunder-proto@1.0.1", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="],
|
||||||
|
|
||||||
"electron-to-chromium": ["electron-to-chromium@1.5.151", "", {}, "sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA=="],
|
"electron-to-chromium": ["electron-to-chromium@1.5.151", "", {}, "sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA=="],
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
"axios": "^1.11.0",
|
"axios": "^1.11.0",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"dompurify": "^3.2.6",
|
|
||||||
"i18next": "^25.4.2",
|
"i18next": "^25.4.2",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"i18next-resources-to-backend": "^1.2.1",
|
"i18next-resources-to-backend": "^1.2.1",
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { useUserContext } from "@/context/user-context";
|
|||||||
import { isValidUrl } from "@/lib/utils";
|
import { isValidUrl } from "@/lib/utils";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { Navigate, useLocation, useNavigate } from "react-router";
|
import { Navigate, useLocation, useNavigate } from "react-router";
|
||||||
import DOMPurify from "dompurify";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export const ContinuePage = () => {
|
export const ContinuePage = () => {
|
||||||
@@ -28,7 +27,7 @@ export const ContinuePage = () => {
|
|||||||
const redirectUri = searchParams.get("redirect_uri");
|
const redirectUri = searchParams.get("redirect_uri");
|
||||||
|
|
||||||
const isValidRedirectUri =
|
const isValidRedirectUri =
|
||||||
redirectUri !== null ? isValidUrl(DOMPurify.sanitize(redirectUri)) : false;
|
redirectUri !== null ? isValidUrl(redirectUri) : false;
|
||||||
const redirectUriObj = isValidRedirectUri
|
const redirectUriObj = isValidRedirectUri
|
||||||
? new URL(redirectUri as string)
|
? new URL(redirectUri as string)
|
||||||
: null;
|
: null;
|
||||||
@@ -37,6 +36,11 @@ export const ContinuePage = () => {
|
|||||||
? redirectUriObj.hostname === rootDomain ||
|
? redirectUriObj.hostname === rootDomain ||
|
||||||
redirectUriObj.hostname.endsWith(`.${rootDomain}`)
|
redirectUriObj.hostname.endsWith(`.${rootDomain}`)
|
||||||
: false;
|
: false;
|
||||||
|
const isAllowedRedirectProto =
|
||||||
|
redirectUriObj !== null
|
||||||
|
? redirectUriObj.protocol === "https:" ||
|
||||||
|
redirectUriObj.protocol === "http:"
|
||||||
|
: false;
|
||||||
const isHttpsDowngrade =
|
const isHttpsDowngrade =
|
||||||
redirectUriObj !== null
|
redirectUriObj !== null
|
||||||
? redirectUriObj.protocol === "http:" &&
|
? redirectUriObj.protocol === "http:" &&
|
||||||
@@ -45,7 +49,7 @@ export const ContinuePage = () => {
|
|||||||
|
|
||||||
const handleRedirect = () => {
|
const handleRedirect = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
window.location.replace(DOMPurify.sanitize(redirectUriObj!.toString()));
|
window.location.replace(redirectUriObj!.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -53,26 +57,32 @@ export const ContinuePage = () => {
|
|||||||
!isLoggedIn ||
|
!isLoggedIn ||
|
||||||
!isValidRedirectUri ||
|
!isValidRedirectUri ||
|
||||||
!isTrustedRedirectUri ||
|
!isTrustedRedirectUri ||
|
||||||
|
!isAllowedRedirectProto ||
|
||||||
isHttpsDowngrade
|
isHttpsDowngrade
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
const auto = setTimeout(() => {
|
||||||
handleRedirect();
|
handleRedirect();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
setTimeout(() => {
|
const reveal = setTimeout(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setShowRedirectButton(true);
|
setShowRedirectButton(true);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(auto);
|
||||||
|
clearTimeout(reveal);
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
return <Navigate to="/login" />;
|
return <Navigate to="/login" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidRedirectUri) {
|
if (!isValidRedirectUri || !isAllowedRedirectProto) {
|
||||||
return <Navigate to="/logout" />;
|
return <Navigate to="/logout" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,11 @@ export const LoginPage = () => {
|
|||||||
description: t("loginOauthSuccessSubtitle"),
|
description: t("loginOauthSuccessSubtitle"),
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
const redirect = setTimeout(() => {
|
||||||
window.location.replace(data.data.url);
|
window.location.replace(data.data.url);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
return () => clearTimeout(redirect);
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
toast.error(t("loginOauthFailTitle"), {
|
toast.error(t("loginOauthFailTitle"), {
|
||||||
@@ -75,11 +77,13 @@ export const LoginPage = () => {
|
|||||||
description: t("loginSuccessSubtitle"),
|
description: t("loginSuccessSubtitle"),
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
const redirect = setTimeout(() => {
|
||||||
window.location.replace(
|
window.location.replace(
|
||||||
`/continue?redirect_uri=${encodeURIComponent(redirectUri ?? "")}`,
|
`/continue?redirect_uri=${encodeURIComponent(redirectUri ?? "")}`,
|
||||||
);
|
);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
return () => clearTimeout(redirect);
|
||||||
},
|
},
|
||||||
onError: (error: AxiosError) => {
|
onError: (error: AxiosError) => {
|
||||||
toast.error(t("loginFailTitle"), {
|
toast.error(t("loginFailTitle"), {
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ export const LogoutPage = () => {
|
|||||||
description: t("logoutSuccessSubtitle"),
|
description: t("logoutSuccessSubtitle"),
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
const redirect = setTimeout(() => {
|
||||||
window.location.replace("/login");
|
window.location.replace("/login");
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
return () => clearTimeout(redirect);
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
toast.error(t("logoutFailTitle"), {
|
toast.error(t("logoutFailTitle"), {
|
||||||
|
|||||||
@@ -34,11 +34,13 @@ export const TotpPage = () => {
|
|||||||
description: t("totpSuccessSubtitle"),
|
description: t("totpSuccessSubtitle"),
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
const redirect = setTimeout(() => {
|
||||||
window.location.replace(
|
window.location.replace(
|
||||||
`/continue?redirect_uri=${encodeURIComponent(redirectUri ?? "")}`,
|
`/continue?redirect_uri=${encodeURIComponent(redirectUri ?? "")}`,
|
||||||
);
|
);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
return () => clearTimeout(redirect);
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
toast.error(t("totpFailTitle"), {
|
toast.error(t("totpFailTitle"), {
|
||||||
|
|||||||
Reference in New Issue
Block a user