mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +00:00
refactor: rework redirects and history storage
This commit is contained in:
@@ -5,8 +5,8 @@ export const App = () => {
|
|||||||
const { isLoggedIn } = useUserContext();
|
const { isLoggedIn } = useUserContext();
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
return <Navigate to="/logout" />;
|
return <Navigate to="/logout" replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Navigate to="/login" />;
|
return <Navigate to="/login" replace />;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
} from "../ui/card";
|
} from "../ui/card";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
|
import { useLocation } from "react-router";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
@@ -17,9 +18,13 @@ interface Props {
|
|||||||
export const DomainWarning = (props: Props) => {
|
export const DomainWarning = (props: Props) => {
|
||||||
const { onClick, appUrl, currentUrl } = props;
|
const { onClick, appUrl, currentUrl } = props;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { search } = useLocation();
|
||||||
|
|
||||||
|
const searchParams = new URLSearchParams(search);
|
||||||
|
const redirectUri = searchParams.get("redirect_uri");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="min-w-xs sm:min-w-sm">
|
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-3xl">{t("domainWarningTitle")}</CardTitle>
|
<CardTitle className="text-3xl">{t("domainWarningTitle")}</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
@@ -31,10 +36,20 @@ export const DomainWarning = (props: Props) => {
|
|||||||
/>
|
/>
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardFooter className="flex flex-col items-stretch">
|
<CardFooter className="flex flex-col items-stretch gap-2">
|
||||||
<Button onClick={onClick} variant="warning">
|
<Button onClick={onClick} variant="warning">
|
||||||
{t("ignoreTitle")}
|
{t("ignoreTitle")}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
window.location.assign(
|
||||||
|
`${appUrl}/login?redirect_uri=${encodeURIComponent(redirectUri || "")}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
{t("goToCorrectDomainTitle")}
|
||||||
|
</Button>
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -54,5 +54,6 @@
|
|||||||
"invalidInput": "Invalid input",
|
"invalidInput": "Invalid input",
|
||||||
"domainWarningTitle": "Invalid Domain",
|
"domainWarningTitle": "Invalid Domain",
|
||||||
"domainWarningSubtitle": "This instance is configured to be accessed from <code>{{appUrl}}</code>, but <code>{{currentUrl}}</code> is being used. If you proceed, you may encounter issues with authentication.",
|
"domainWarningSubtitle": "This instance is configured to be accessed from <code>{{appUrl}}</code>, but <code>{{currentUrl}}</code> is being used. If you proceed, you may encounter issues with authentication.",
|
||||||
"ignoreTitle": "Ignore"
|
"ignoreTitle": "Ignore",
|
||||||
|
"goToCorrectDomainTitle": "Go to correct domain"
|
||||||
}
|
}
|
||||||
@@ -54,5 +54,6 @@
|
|||||||
"invalidInput": "Invalid input",
|
"invalidInput": "Invalid input",
|
||||||
"domainWarningTitle": "Invalid Domain",
|
"domainWarningTitle": "Invalid Domain",
|
||||||
"domainWarningSubtitle": "This instance is configured to be accessed from <code>{{appUrl}}</code>, but <code>{{currentUrl}}</code> is being used. If you proceed, you may encounter issues with authentication.",
|
"domainWarningSubtitle": "This instance is configured to be accessed from <code>{{appUrl}}</code>, but <code>{{currentUrl}}</code> is being used. If you proceed, you may encounter issues with authentication.",
|
||||||
"ignoreTitle": "Ignore"
|
"ignoreTitle": "Ignore",
|
||||||
|
"goToCorrectDomainTitle": "Go to correct domain"
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ export const ContinuePage = () => {
|
|||||||
|
|
||||||
const handleRedirect = () => {
|
const handleRedirect = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
window.location.replace(redirectUriObj!.toString());
|
window.location.assign(redirectUriObj!.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -79,16 +79,21 @@ export const ContinuePage = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
return <Navigate to="/login" />;
|
return (
|
||||||
|
<Navigate
|
||||||
|
to={`/login?redirect_uri=${encodeURIComponent(redirectUri || "")}`}
|
||||||
|
replace
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidRedirectUri || !isAllowedRedirectProto) {
|
if (!isValidRedirectUri || !isAllowedRedirectProto) {
|
||||||
return <Navigate to="/logout" />;
|
return <Navigate to="/logout" replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isTrustedRedirectUri) {
|
if (!isTrustedRedirectUri) {
|
||||||
return (
|
return (
|
||||||
<Card className="min-w-xs sm:min-w-sm">
|
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-3xl">
|
<CardTitle className="text-3xl">
|
||||||
{t("continueUntrustedRedirectTitle")}
|
{t("continueUntrustedRedirectTitle")}
|
||||||
@@ -126,7 +131,7 @@ export const ContinuePage = () => {
|
|||||||
|
|
||||||
if (isHttpsDowngrade) {
|
if (isHttpsDowngrade) {
|
||||||
return (
|
return (
|
||||||
<Card className="min-w-xs sm:min-w-sm">
|
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-3xl">
|
<CardTitle className="text-3xl">
|
||||||
{t("continueInsecureRedirectTitle")}
|
{t("continueInsecureRedirectTitle")}
|
||||||
|
|||||||
@@ -113,8 +113,17 @@ export const LoginPage = () => {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isLoggedIn && redirectUri) {
|
||||||
|
return (
|
||||||
|
<Navigate
|
||||||
|
to={`/continue?redirect_uri=${encodeURIComponent(redirectUri)}`}
|
||||||
|
replace
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
return <Navigate to="/logout" />;
|
return <Navigate to="/logout" replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const LogoutPage = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
redirectTimer.current = window.setTimeout(() => {
|
redirectTimer.current = window.setTimeout(() => {
|
||||||
window.location.replace("/login");
|
window.location.assign("/login");
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
@@ -50,7 +50,7 @@ export const LogoutPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
return <Navigate to="/login" />;
|
return <Navigate to="/login" replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export const TotpPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!totpPending) {
|
if (!totpPending) {
|
||||||
return <Navigate to="/" />;
|
return <Navigate to="/" replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"tinyauth/internal/utils"
|
"tinyauth/internal/utils"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -34,7 +36,6 @@ type AppContextResponse struct {
|
|||||||
|
|
||||||
type ContextControllerConfig struct {
|
type ContextControllerConfig struct {
|
||||||
ConfiguredProviders []string
|
ConfiguredProviders []string
|
||||||
DisableContinue bool
|
|
||||||
Title string
|
Title string
|
||||||
GenericName string
|
GenericName string
|
||||||
AppURL string
|
AppURL string
|
||||||
@@ -90,13 +91,15 @@ func (controller *ContextController) userContextHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (controller *ContextController) appContextHandler(c *gin.Context) {
|
func (controller *ContextController) appContextHandler(c *gin.Context) {
|
||||||
|
appUrl, _ := url.Parse(controller.Config.AppURL) // no need to check error, validated on startup
|
||||||
|
|
||||||
c.JSON(200, AppContextResponse{
|
c.JSON(200, AppContextResponse{
|
||||||
Status: 200,
|
Status: 200,
|
||||||
Message: "Success",
|
Message: "Success",
|
||||||
ConfiguredProviders: controller.Config.ConfiguredProviders,
|
ConfiguredProviders: controller.Config.ConfiguredProviders,
|
||||||
Title: controller.Config.Title,
|
Title: controller.Config.Title,
|
||||||
GenericName: controller.Config.GenericName,
|
GenericName: controller.Config.GenericName,
|
||||||
AppURL: controller.Config.AppURL,
|
AppURL: fmt.Sprintf("%s://%s", appUrl.Scheme, appUrl.Host),
|
||||||
RootDomain: controller.Config.RootDomain,
|
RootDomain: controller.Config.RootDomain,
|
||||||
ForgotPasswordMessage: controller.Config.ForgotPasswordMessage,
|
ForgotPasswordMessage: controller.Config.ForgotPasswordMessage,
|
||||||
BackgroundImage: controller.Config.BackgroundImage,
|
BackgroundImage: controller.Config.BackgroundImage,
|
||||||
|
|||||||
Reference in New Issue
Block a user