mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-02-26 10:52:02 +00:00
Compare commits
2 Commits
ce8493239e
...
refactor/s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff771c5c22 | ||
|
|
d7b00ffeea |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,3 +39,6 @@ __debug_*
|
|||||||
|
|
||||||
# infisical
|
# infisical
|
||||||
/.infisical.json
|
/.infisical.json
|
||||||
|
|
||||||
|
# traefik data
|
||||||
|
/traefik
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -10,7 +10,7 @@ BUILD_TIMESTAMP := $(shell date '+%Y-%m-%dT%H:%M:%S')
|
|||||||
BIN_NAME := tinyauth-$(GOARCH)
|
BIN_NAME := tinyauth-$(GOARCH)
|
||||||
|
|
||||||
# Development vars
|
# Development vars
|
||||||
DEV_COMPOSE := $(shell test -f "docker-compose.test.yml" && echo "docker-compose.test.yml" || echo "docker-compose.dev.yml" )
|
DEV_COMPOSE := $(shell test -f "docker-compose.test.yml" && echo "docker-compose.test.yml" || echo "docker-compose.yml" )
|
||||||
PROD_COMPOSE := $(shell test -f "docker-compose.test.prod.yml" && echo "docker-compose.test.prod.yml" || echo "docker-compose.example.yml" )
|
PROD_COMPOSE := $(shell test -f "docker-compose.test.prod.yml" && echo "docker-compose.test.prod.yml" || echo "docker-compose.example.yml" )
|
||||||
|
|
||||||
# Deps
|
# Deps
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ services:
|
|||||||
image: traefik/whoami:latest
|
image: traefik/whoami:latest
|
||||||
labels:
|
labels:
|
||||||
traefik.enable: true
|
traefik.enable: true
|
||||||
traefik.http.routers.whoami.rule: Host(`whoami.127.0.0.1.sslip.io`)
|
traefik.http.routers.whoami.rule: Host(`whoami.example.com`)
|
||||||
traefik.http.routers.whoami.middlewares: tinyauth
|
traefik.http.routers.whoami.middlewares: tinyauth
|
||||||
|
|
||||||
tinyauth-frontend:
|
tinyauth-frontend:
|
||||||
@@ -27,7 +27,7 @@ services:
|
|||||||
- 5173:5173
|
- 5173:5173
|
||||||
labels:
|
labels:
|
||||||
traefik.enable: true
|
traefik.enable: true
|
||||||
traefik.http.routers.tinyauth.rule: Host(`tinyauth.127.0.0.1.sslip.io`)
|
traefik.http.routers.tinyauth.rule: Host(`tinyauth.example.com`)
|
||||||
|
|
||||||
tinyauth-backend:
|
tinyauth-backend:
|
||||||
container_name: tinyauth-backend
|
container_name: tinyauth-backend
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export const DomainWarning = (props: Props) => {
|
|||||||
i18nKey="domainWarningSubtitle"
|
i18nKey="domainWarningSubtitle"
|
||||||
values={{ appUrl, currentUrl }}
|
values={{ appUrl, currentUrl }}
|
||||||
components={{ code: <code /> }}
|
components={{ code: <code /> }}
|
||||||
shouldUnescape={true}
|
|
||||||
/>
|
/>
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|||||||
@@ -32,34 +32,43 @@ export const ContinuePage = () => {
|
|||||||
cookieDomain,
|
cookieDomain,
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRedirect = useCallback(() => {
|
const urlHref = url?.href;
|
||||||
|
|
||||||
|
const hasValidRedirect = valid && allowedProto;
|
||||||
|
const showUntrustedWarning =
|
||||||
|
hasValidRedirect && !trusted && !disableUiWarnings;
|
||||||
|
const showInsecureWarning =
|
||||||
|
hasValidRedirect && httpsDowngrade && !disableUiWarnings;
|
||||||
|
const shouldAutoRedirect =
|
||||||
|
isLoggedIn &&
|
||||||
|
hasValidRedirect &&
|
||||||
|
!showUntrustedWarning &&
|
||||||
|
!showInsecureWarning;
|
||||||
|
|
||||||
|
const redirectToTarget = useCallback(() => {
|
||||||
|
if (!urlHref || hasRedirected.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hasRedirected.current = true;
|
hasRedirected.current = true;
|
||||||
|
window.location.assign(urlHref);
|
||||||
|
}, [urlHref]);
|
||||||
|
|
||||||
|
const handleRedirect = useCallback(() => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
window.location.assign(url!);
|
redirectToTarget();
|
||||||
}, [url]);
|
}, [redirectToTarget]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoggedIn) {
|
if (!shouldAutoRedirect) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasRedirected.current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(!valid || !allowedProto || !trusted || httpsDowngrade) &&
|
|
||||||
!disableUiWarnings
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto = setTimeout(() => {
|
const auto = setTimeout(() => {
|
||||||
handleRedirect();
|
redirectToTarget();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
const reveal = setTimeout(() => {
|
const reveal = setTimeout(() => {
|
||||||
setIsLoading(false);
|
|
||||||
setShowRedirectButton(true);
|
setShowRedirectButton(true);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
@@ -67,18 +76,7 @@ export const ContinuePage = () => {
|
|||||||
clearTimeout(auto);
|
clearTimeout(auto);
|
||||||
clearTimeout(reveal);
|
clearTimeout(reveal);
|
||||||
};
|
};
|
||||||
}, [
|
}, [shouldAutoRedirect, redirectToTarget]);
|
||||||
isLoggedIn,
|
|
||||||
hasRedirected,
|
|
||||||
valid,
|
|
||||||
allowedProto,
|
|
||||||
trusted,
|
|
||||||
httpsDowngrade,
|
|
||||||
disableUiWarnings,
|
|
||||||
setIsLoading,
|
|
||||||
handleRedirect,
|
|
||||||
setShowRedirectButton,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
return (
|
return (
|
||||||
@@ -89,11 +87,11 @@ export const ContinuePage = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid || !allowedProto) {
|
if (!hasValidRedirect) {
|
||||||
return <Navigate to="/logout" replace />;
|
return <Navigate to="/logout" replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!trusted && !disableUiWarnings) {
|
if (showUntrustedWarning) {
|
||||||
return (
|
return (
|
||||||
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -108,13 +106,12 @@ export const ContinuePage = () => {
|
|||||||
code: <code />,
|
code: <code />,
|
||||||
}}
|
}}
|
||||||
values={{ cookieDomain }}
|
values={{ cookieDomain }}
|
||||||
shouldUnescape={true}
|
|
||||||
/>
|
/>
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardFooter className="flex flex-col items-stretch gap-2">
|
<CardFooter className="flex flex-col items-stretch gap-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleRedirect()}
|
onClick={handleRedirect}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
>
|
>
|
||||||
@@ -132,7 +129,7 @@ export const ContinuePage = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpsDowngrade && !disableUiWarnings) {
|
if (showInsecureWarning) {
|
||||||
return (
|
return (
|
||||||
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -151,7 +148,7 @@ export const ContinuePage = () => {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardFooter className="flex flex-col items-stretch gap-2">
|
<CardFooter className="flex flex-col items-stretch gap-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleRedirect()}
|
onClick={handleRedirect}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
variant="warning"
|
variant="warning"
|
||||||
>
|
>
|
||||||
@@ -179,7 +176,7 @@ export const ContinuePage = () => {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
{showRedirectButton && (
|
{showRedirectButton && (
|
||||||
<CardFooter className="flex flex-col items-stretch">
|
<CardFooter className="flex flex-col items-stretch">
|
||||||
<Button onClick={() => handleRedirect()}>
|
<Button onClick={handleRedirect}>
|
||||||
{t("continueRedirectManually")}
|
{t("continueRedirectManually")}
|
||||||
</Button>
|
</Button>
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ export const LogoutPage = () => {
|
|||||||
username: email,
|
username: email,
|
||||||
provider: oauthName,
|
provider: oauthName,
|
||||||
}}
|
}}
|
||||||
shouldUnescape={true}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Trans
|
<Trans
|
||||||
@@ -79,7 +78,6 @@ export const LogoutPage = () => {
|
|||||||
values={{
|
values={{
|
||||||
username,
|
username,
|
||||||
}}
|
}}
|
||||||
shouldUnescape={true}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
|
|||||||
Reference in New Issue
Block a user